What compiler parameter / library do I need to use to detect detect_or_t?

I am trying to use std::experimental::detect_or_t from <experimental/type_traits> .

Which compiler, option, version or library do I need to compile the following example from http://en.cppreference.com/w/cpp/experimental/is_detected ?

 #include <experimental/type_traits> #include <cstddef> template<class T> using diff_t = typename T::difference_type; template <class Ptr> using difference_type = std::experimental::detected_or_t<std::ptrdiff_t, diff_t, Ptr>; struct Meow { using difference_type = int; }; struct Purr {}; int main() { static_assert(std::is_same<difference_type<Meow>, int>::value, "Meow difference_type should be int!"); static_assert(std::is_same<difference_type<Purr>, std::ptrdiff_t>::value, "Purr difference_type should be ptrdiff_t!"); } 

I tried using clang++ -std=c++14 and g++ -std=c++14 . Also with -std=c++1y and -std=c++17 . I always get the following:

main.cpp:8:44: error: 'detected_or_t' in namespace 'std::experimental' does not name a template type

+1
source share
1 answer

These features were first added to libstdc ++ in GCC 6.1.0, as described in the GCC 6 release notes :

  • Experimental support for most of the features of the second version of the TS Library Basics.

And the implementation status tables in the manual, at https://gcc.gnu.org/onlinedocs/gcc-6.1.0/libstdc++/manual/manual/status.html#table.cxx1z_ts_status

I'm not sure about libC ++, but they are not supported by the version in Clang 3.9.1, but they are supported by the current line, so I think they first appeared in Clang 4.0.0

+1
source

Source: https://habr.com/ru/post/1238217/


All Articles