There have been many, many, many questions and answers regarding the trailing return type, auto return type deduction and the very useful decltype(auto). But I failed to find an answer to whether the trailing return type is needed at all since we have decltype(auto). Are there cases that the trailing return type solves, where decltype(auto) either cannot be used or doesn't work (gives unexpected / incorrect results) and the trailing return type was needed in the first place?
Does decltype(auto) make trailing return type obsolete?
482 Views Asked by Fureeish At
2
There are 2 best solutions below
Related Questions in C++
- C++ using std::vector across boundaries
- Linked list without struct
- Connecting Signal QML to C++ (Qt5)
- how to get the reference of struct soap inherited in C++ Proxy/Service class
- Why we can't assign value to pointer
- Conversion of objects in c++
- shared_ptr: "is not a type" error
- C++ template using pointer and non pointer arguments in a QVector
- C++ SFML 2.2 vectors
- Lifetime of temporary objects
- I want to be able to use 4 different variables in a select statement in c ++
- segmentation fault: 11, extracting data in vector
- How to catch delay-import dll errors (missing dll or symbol) in MinGW(-w64)?
- How can I print all the values in this linked list inside a hash table?
- Configured TTL for A record(s) backing CNAME records
Related Questions in C++17
- why declare constrexpr constructors for classes with non-trivial destructors (e.g. unique_ptr, std::variant)
- Passing lambda as template parameter to templated by function-pointer function
- std::vector on forward declared type
- Is there a tuple for_each() that returns a tuple of all values returned from the functions invoked?
- How to use allocators in modern C++
- I made a C++17 burrito for mapping over tuples, and anything that has begin() end() iterators. Is it possible to get rid of these factory functions?
- Do overloaded logical operators && and || short-circuit since C++17?
- Why the equivalent representation of a range-for required to be updated?
- In C++17, why do associative containers have an `erase` member function that takes (non-`const`) `iterator`?
- c++ variant class member stored by reference
- How does std::apply forward parameters without explicit std::forward?
- Neither clang nor g++ compile the snippet below. Why?
- constexpr recursive function using if constexpr or not
- Why is std::shared_ptr::unique() deprecated?
- Can constexpr-if-else bodies return different types in constexpr auto function?
Related Questions in C++20
- Conditionally trivial destructor
- Can a namespace (be a/satisfy a) Concept?
- Boost Hana Concepts implementation
- C++ concepts loop
- Moving in range-based loop in generic C++ code?
- Can I execute on get my `std::future` and wait on it too?
- C++20 coroutines, std return type and state persistancy
- Will C++20 modules change the anatomy of static and shared libraries?
- How to return unique_ptr of an array created inside my function?
- Does clang++ 12 support C++20 std::construct_at?
- Visiting std::variant with lambdas in C++20
- How to write a C++ concept restricting the template to std::map and std::unordered_map
- C++20 #import ""-statement: Will it be possible to use multiple preprocessed header files
- Exporting Concept From Module
- != auto generated from == in C++20?
Related Questions in TRAILING-RETURN-TYPE
- the order of member variable in class template
- Trailing Return Type on operator* In Template Class
- How to use trailing return type with a templated class member
- What is the purpose of this trailing return type declaration?
- Trailing return type in non-template functions
- Using this and attributes in member function trailing return types?
- How to use auto return and decltype when class members involved with c++11?
- Function-scope name in generic lambda trailing return type won't compile (MSVC)
- Conditional overloading with trailing-return-type possible?
- Template member functions with trailing return type, giving errors even if unused
- Compile time access to tuple item with an enum value
- Trailing return types and tag dispatching
- Using trailing return type to prevent function template instantiation?
- How to establish trailing return type of lambda function that use template functions?
- Can abstract types be used as the return type of a pure virtual function?
Related Questions in DECLTYPE-AUTO
- Using decltype(auto) in C++ non-type template parameter
- error: use of 'decltype(auto) X before deduction of 'auto' (for generated lambda)
- Why are adornment to auto allowed in the return type of a function
- decltype(auto) return type and lifetime issues
- Why does this const function return a non-const reference?
- What are some uses of decltype(auto)?
- decltype of entity that may be captured: should it yield the type of the entity outside of the lambda?
- Why decltype(auto) infers T& as return type, while dedicated T& does not?
- What is the difference between returning auto&& and decltype(auto)?
- Return element of pair with perfect forwarding
- Why doesn't decltype(auto) return the address of the lvalue?
- decltype(auto) type deduction: return x vs. return (x)
- Is the correct return type deduced with decltype(auto)?
- Why are variable types that appear the same not being recognized as the same?
- Declare uninitialized auto variables with type of Returning function
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
decltype(auto)(and more generally deduced return type) and trailing return type are orthogonal features.You can have:
decltype(auto) f() {}auto f() -> decltype(auto) {}Trailing return type
trailing return type is fine especially to have access to context we don't have before the function name
as for template:
versus
or for dependent name in class:
versus
The only place where it is required is for lambda (if you have/want to specify return type explicitly):
[]() -> some_type {/*...*/}[]() -> auto {/*...*/}(which is equivalent to[]() {/*...*/})[]() -> decltype(auto) {/*...*/}Case when we have to defining return type of lambda is when it should return reference type.
Deduced return type
Done with
decltype(auto)andauto.decltype(auto)andautodeduction type differs, mostly asT&&andT.Deduced return type requires definition of the body.
They also doesn't allow SFINAE, as there are no substitution.