using-declaration

Why can an (irrelevant) using declaration reconcile overload ambiguity with Argument-Dependent Lookup?

六眼飞鱼酱① 提交于 2019-12-10 19:07:23
问题 This is a follow up of the question here on function overload with Argument-Dependent Lookup (ADL). I wanted to check my understanding of the rules under these circumstances so I wrote some test code. First, there is no swap for HasPtr class in std, of course, so I wrote a namespace of my own which contains a HasPtr version of swap in addition to the one already defined in global scope. The using declaration works as what I expected -- an error of ambiguity was produced because there is a

using and overloading a template member function of a base class?

邮差的信 提交于 2019-12-08 22:10:17
问题 In the following, struct Y overloads X 's member function f . Both overloads are template functions, but take different arguments ( typename and int ), to be explicitly specified: struct X { template <typename> static bool f() { return true; } }; struct Y : public X { using X::f; template <int> static bool f() { return false; } }; int main() { std::cout << Y::f <void>() << " " << Y::f <0>() << std::endl; } This prints 1 0 using gcc, as expected. However, clang (3.3) complains that [...] error

Using declaration (Derived class)

会有一股神秘感。 提交于 2019-12-08 19:44:04
问题 struct B1{ int d; void fb(){}; }; struct B2 : B1{ using B1::d; using B1::fb; int d; // why this gives error? void fb(){} // and this does not? }; int main(){} Is it because, B1::fb() is treated as B1::fb(B1*) and B2::fb() treated as B2::fb(B2*) ? That is, does the implicit parameter, help in distinguishing these? $13.3.1/4- For nonconversion functions introduced by a using-declaration into a derived class, the function is considered to be a member of the derived class for the purpose of

passing a parameter pack over a legacy function signature using forward_as_tuple

寵の児 提交于 2019-12-08 11:42:24
问题 In my app I would like to pass in a parameter pack over a legacy function signature, and change the values. Here is code that illustrates my question with my attempts as comments: #include <tuple> #include <cassert> void LegacySignature( void* param ); template< typename... ArgsT > // using ???; // attempt: can 'template alias' or 'using declaration' make the pack's type visible so I can use it inside the LegacyFunction? void MyFunc( ArgsT&... args ) { auto userArgsTuple = std::forward_as

A way to use all the unqualified names in a C++0x enum class?

时光总嘲笑我的痴心妄想 提交于 2019-12-07 04:58:44
问题 The new C++ (C++0x or C++11) has an new kind of enum, an "enum class" where the names are scoped to the enum (among other things). enum class E { VAL1, VAL2 }; void fun() { E e = E::VAL1; // Qualified name } I'm wondering, however, if I can selectively use the unqualified name in a certain scope. Something like: void fun() { using E::*; E e = VAL1; switch (e) { case VAL2: ... I see I can write using E::VAL1 and get one value. But I don't want to do that for every value of a larger enum. 回答1:

Accessing types from dependent base classes

吃可爱长大的小学妹 提交于 2019-12-06 19:14:06
问题 Does anyone know why using-declarations don't seem to work for importing type names from dependent base classes? They work for member variables and functions, but at least in GCC 4.3, they seem to be ignored for types. template <class T> struct Base { typedef T value_type; }; template <class T> struct Derived : Base<T> { // Version 1: error on conforming compilers value_type get(); // Version 2: OK, but unwieldy for repeated references typename Base<T>::value_type get(); // Version 3: OK, but

Using-declaration of an existing namespace type vs creating a type alias

℡╲_俬逩灬. 提交于 2019-12-06 02:57:59
问题 This is not a question about the difference between using and typedef for creating type aliases. I would like to provide access to an existing type from a namespace inside a code block or a function. I found two different ways : I can "include" the type with a using declaration : using typename mynamespace::mytype; Or I can create a type alias : typedef mynamespace::mytype mytype; using mytype = mynamespace::mytype; //C++11 Is there any difference ? What are the pros and cons of each syntax ?

Redefinition inconsistency in clang between struct and int

﹥>﹥吖頭↗ 提交于 2019-12-06 01:27:01
The following program gives no error when compiling with clang: namespace X { struct i {}; } namespace Y { using X::i; struct i {}; } int main() {} Let's use int instead of struct, then we get: namespace X { int i; } namespace Y { using X::i; int i; } int main() {} This program gives a redefinition error when compiling with clang. The only difference between the programs is the kind of entity used (struct or int), but one compiles without errors and the other gives a redefinition error. Does this indicate a bug in clang? Maybe the standard is ambiguous what a redefinition is when it comes to

A way to use all the unqualified names in a C++0x enum class?

亡梦爱人 提交于 2019-12-05 05:56:44
The new C++ (C++0x or C++11) has an new kind of enum, an "enum class" where the names are scoped to the enum (among other things). enum class E { VAL1, VAL2 }; void fun() { E e = E::VAL1; // Qualified name } I'm wondering, however, if I can selectively use the unqualified name in a certain scope. Something like: void fun() { using E::*; E e = VAL1; switch (e) { case VAL2: ... I see I can write using E::VAL1 and get one value. But I don't want to do that for every value of a larger enum. There is no way to do this in C++11. Just in case you are not aware of it - you get the E::Val1 notation

Equality of template aliases

£可爱£侵袭症+ 提交于 2019-12-05 01:23:03
I try to create template alias which cannot be distinguished from original. So, I create traits to check when 2 templates (not types) are equal: template <template <class...> class C1, template <class...> class C2> struct is_same_template : std::false_type {}; template <template <class...> class C1> struct is_same_template<C1, C1> : std::true_type {}; Now test it: // Expected alias template <typename ... Ts> using V_Ts = std::vector<Ts...>; // Variadic // Fallback alias template <typename T, typename A> using V = std::vector<T, A>; // Exact count static_assert(!is_same_template<std::vector, V