logo
Tags down

shadow

Why does decltype(auto) not work as expected?


By : Paolino Sviluppatore
Date : October 16 2020, 08:10 PM
I wish did fix the issue. It's a GCC bug.
decltype(auto) = e is equivalent to decltype(e) and yield the declared type of e.
code :
auto&& t = n;
static_assert(std::is_same_v<decltype(t), int&>); // true
int&& r = 9;
static_assert(std::is_same_v<decltype(r), int&&>); // true (1)

decltype(auto) t = r; // fail with the same error you got.


Share : facebook icon twitter icon

decltype(auto) in member function ignores invalid body, decltype(expr) fails


By : user3436101
Date : March 29 2020, 07:55 AM
around this issue I have a simple templated wrapper struct with a member function calling .error() on an object of its template type. , The difference between the versions
code :
decltype(auto) f();
auto f() -> decltype(t.error());
template<typename U = T>
auto f() -> decltype( std::declval<U&>().error() );
template<typename U = T>
auto f() -> decltype( std::declval<U&>().error() )
{
    return t.error();
}
#include <type_traits>

template<typename T> struct type_is { using type = T; };

template <typename T>
struct Wrapper {
    T t;

    template<typename U=T, typename=void>
    struct error_return_type_or_void : type_is<void> {};

    template<typename U>
    struct error_return_type_or_void
        <U, decltype(std::declval<U&>().error(), void())>
    : type_is<decltype(std::declval<U&>().error())> {};

    auto f() -> typename error_return_type_or_void<>::type {
        return t.error();
    }
};

Inside of a class, why `auto b() -> decltype(a()) {}` works, but `decltype(a()) b() {}` does not?


By : victor m
Date : March 29 2020, 07:55 AM
Hope that helps Since a is a non-static member function, a() is interpreted as (*this).a(). Quoting in part from [expr.prim.general]/3,

What is difference between decltype(auto) and decltype(returning expr) as return type?


By : JUNJIE CAI
Date : March 29 2020, 07:55 AM
it fixes the issue Yes there is a difference. The first one will detect the return type based on the return expression in the body of the function.
The second one will not also set the return type to the type of the expression inside decltype(), but will also apply expression sfinae on it. That means that if the expression inside decltype is not valid, the compiler will search for another valid overload. Whereas the first version will be a hard error.
code :
template<typename T>
auto fun(T a) -> decltype(a.f()) { return a.f(); }

template<typename T>
auto fun(T a) -> decltype(a.g()) { return a.g(); }

struct SomeType {
    int g() { return 0; }
};

fun(SomeType{});

std::is_same doesn't work through decltype of constexpr auto variable


By : Maria Esther Padilla
Date : March 29 2020, 07:55 AM
it fixes the issue It's a trivial error, really, but hard to spot unfortunately. The issue you face is because constexpr implies const. So in your example type is const tuple<...>, which is not the same type as the non cv-qualified type you check. A short fix to the alias should make your test pass:
code :
using type = std::remove_const_t<decltype(value)>;

c++ 11 Trailing return type with decltype does not work as expected


By : Md joynal Abedin
Date : March 29 2020, 07:55 AM
hope this fix your issue It doesn't matter what the condition with the ?: operator is. The result type is calculated as a common type of the second and third operand. Here is part of how the common type and the value category of the ?: operator are calculated, see cppreference.com for the full details:
If the second and third operand are lvalues of the same type, then the result type will be a lvalue of that type.
Related Posts Related Posts :
  • Malloc of pointer to an array- C++
  • Changing audio stream from physical input
  • Sorting a Vector of a custom class with std::sort() causes a segmentation fault
  • fastest way to read the last line of a string?
  • std::num_put issue with nan-boxing due to auto-cast from float to double
  • Difficulty with map's find function
  • Visual C++ executable will not run without Boost DLLs
  • #include <mutex> causes the bind() function call to throw errors at compile time, why?
  • Random_shuffle alternative in C++Builder6
  • C++ unique_ptr initialization
  • Is it really safe not to check in the copy assignemt operator whether an object is assigned to itself?
  • How to avoid passing param to template instantiation of reference-based helper class
  • c++ program not printing 2d vector grid properly but is close
  • Why isn't my array incrementing properly?
  • How to create your own Function for Async operation in c++ UWP?
  • C++ accessing a variable in a union struct
  • What does a implicitly defined destructor do
  • Member was not declared in base class template
  • Overloading << sign follow by a boolean expression
  • looser throw specifier for virtual function : GCC 4.9 complains but MSVC
  • How to print and read at in the same line in Haskell?
  • SFINAE with Templated class Member functions
  • how to declare char * with input of {"data": "0001"}'
  • c++ program compile with LAPACK library
  • Enum in C++ Classes
  • Sort Specific Column of 2D int array (C++)
  • Unordered_map find const wchar_t*
  • OK to use these two parameters each independently, but fail to have both
  • Two classes with same, standalone, hidden functionality
  • C++: Instantiate object with no namespace
  • qml set text property from c++
  • Confused Backtrace of GDB while analysing core dump file at ../stdlib/strtod_l.c:734
  • syscall.MustLoadDll.MustFindProc throws "The specified procedure could not be found"
  • Why does structured binding not work as expected on struct?
  • Using lambda expression as Compare for std::set, when it's inside a vector
  • C++ Can't reference key of the map
  • Generic QuickSort implemented with vector and iterators C++
  • purpose for wait_for function in condition variable - C++11
  • Can I fill a template parameter with a nested class in this class?
  • Inconsistency parsing numeric literals according to C++ Standard's grammar
  • Array with fixed size at runtime
  • Which is better to check if a character exists in a std::string? find or find_first_of?
  • Insert element (TinyXml)
  • My argv[] in main always returns 0 when converted to integer
  • Indirect Path to Files, when program is called from somewhere else
  • Find all reachable vertices in a Boost BGL graph efficiently
  • Paint context and tool in maya for custom blendshape
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org