You said yourself, decltype (*this) is T&. decltype (*this) const & tries to form a reference to a reference (T& const &). decltype triggers the reference collapsing rule 8.3.2p6. But it doesn't collapse the way you'd like. You could say decltype(this) const&, but that would be T* const& -- a...

You don't name the argument - you just want the type: std::multiset<Sales_data, bool (*)(const Sales_data &, const Sales_data &) > bookstore(&compareIsbn); What you had was declaring a function pointer of that type named pf. You also don't need the &, just compareIsbn is fine. ...

decltype(comp)* is just a pointer to a function with the signature bool(Phone const&, Phone const&). It gets value initialized to nullptr. The std::initializer_list constructor of std::multiset uses this as the default paramter for the Compare object. Since you have initialized your std::multiset with a null function pointer as the comparator,...

7.1.6.2 [dcl.type.simple] For an expression e, the type denoted by decltype(e) is defined as follows: — if e is an unparenthesized id-expression or an unparenthesized class member access (5.2.5), decltype(e) is the type of the entity named by e. If there is no such entity, or if e names a...

I have been troubled for hours or days around such problems. Typically gcc wants this-> but clang does not. In some cases Foo:: also helps but there have been cases where I have given up using the member names. The following is only using the type names and (though more...

decltype() is a built-in operator, not a function from the std namespace like std::declval<T>(). If you want to shorten the syntax with an alias template, you can declare one as shown below: #include <type_traits> template <typename C> using IT = I<C, typename std::remove_reference<decltype(std::declval<C&>().fn(0))>::type>; template <typename C> IT<C> fn(C& c) {...

The error message for your first option is due to the fact that in std::declval<func_type>()(std::forward<Ts>(ts)...) you're trying to call the f1 functor with two arguments of type double (the ones passed to operator()), but it takes a std::pair (func_type refers to the type of the first functor in the tuple)....

It actually works but the syntax is different: template decltype(foo<int>) foo<int>; decltype gives you a type but the explicit instantiation requires a declaration which is a type followed by a name. Tried with GCC 4.9.1; it works as expected and compiles without any warnings even with the -pedantic flag....

String literals are lvalues ([expr.prim.general]/p1): A literal is a primary expression. Its type depends on its form (2.13). A string literal is an lvalue; all other literals are prvalues. decltype(expr) returns an lvalue-reference when the expression expr is an lvalue expression ([dcl.type.simple]/p4): For an expression e, the type denoted by...

In C++, you can't use a name that hasn't been introduced (declared) in a declaration, including in a decltype for a trailing return type. So you must reorder your declarations : struct A { int m_count; auto count() -> decltype(m_count) { return m_count; } }; ...

It is expected to have only members declared prior to the function declaration. As seen in §5.1.1 bullet 3 of the standard : If a declaration declares a member function … [ Note: only class members declared prior to the declaration are visible. —end note ] ...

Let's patch it up. std::result_of expects only types, its result should be retrieve from its type inner typedef, and you need typename to access said typedef because it depends on a template parameter. template<typename T> using to_string_t = typename std::result_of<decltype(std::to_string)(T)>::type; ^^^^^^^^ ^^^^^^^^ ^^^^^^ Or in C++14, you can drop ::type...

Yes, the first one uses the const overload and the second one the non-const one. That's because _t is const in the first case and non-const in the second one. Which one is used in the type alias depends on the type of data. Is it const? If so, the...

Visual Studio 2012 which, based on your project directory, is the one you're using, does not support type aliasing. It's a C++11 feature and does not make an appearance in the MSDN documentation, even for VS2013, though I think that may just be a doc error on their part -...

So based on the comments we can conclude: This is a bug in VS2015 preview There are workarounds The bug has been reported The bug is that: The compiler should have deduced the return type to be string It actually deduced it to be string && Thus it destroyed the...

Return type forwarding in generic code For non-generic code, like the initial example you gave, you can manually select to get a reference as a return type: auto const& Example(int const& i) { return i; } but in generic code you want to be able to perfectly forward a return...

You can use std::remove_reference to make it a non-reference type: std::numeric_limits< std::remove_reference<decltype(*p)>::type >::max(); Live demo or: std::numeric_limits< std::remove_reference_t<decltype(*p)> >::max(); for something slightly less verbose....

It's an expression. [expr.type.conv]/p2-3: The expression T(), where T is a simple-type-specifier or typename-specifier for a non-array complete object type or the (possibly cv-qualified) void type, creates a prvalue of the specified type, whose value is that produced by value-initializing (8.5) an object of type T; no initialization is done...

When you encounter a problem like this, let the compiler help you. Remove the (...) overload to force a compilation error, and see what GCC tells you: test.cc: In instantiation of ‘constexpr const bool has_enum_name<Foo>::value’: test.cc:51:71: required from here test.cc:18:33: error: no matching function for call to ‘has_enum_name<Foo>::test(int)’ !(std::is_same<decltype(test<T>(0)),std::false_type>::value); ^...

It depends on entirely on what you want to do in the cases of cv T* and cv T[N]. If in all of those cases you just want T, then you'll need to write a type trait: template <typename T> struct tag { using type = T; }; template <typename...

In § 7.1.6.4 [dcl.spec.auto] If the placeholder is the decltype(auto) type-specifier, the declared type of the variable or return type of the function shall be the placeholder alone. The type deduced for the variable or return type is determined as described in 7.1.6.2, as though the initializer had been the...

Even when the compiler knows that the else block won't be entered, the code inside it must be syntactically valid. Consider what happens here when p is double: if (current == i){ return p.el0; } else { return get_my(p.el1, i, current++); } get_my gets instantiated and inside it the compiler...