我需要使用什么编译器选项/库来使用detect_or_t类型特征? [英] What compiler option/library do I need to use detect_or_t type trait?
问题描述
我试图从< experimental / type_traits>
使用 std :: experimental :: detect_or_t
。
我需要编译以下示例的编译器,选项,版本或库来从 http://en.cppreference.com/w/cpp/experimental/is_detected
#include< experiments / type_traits>
#include< cstddef>
模板< class T>
使用diff_t = typename T :: difference_type;
模板< 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应该是int!
static_assert(std :: is_same< difference_type< Purr>,std :: ptrdiff_t> :: value,Purr的difference_type应该是ptrdiff_t!);
我试过使用 clang ++ -std = c ++ 14
和 g ++ -std = c ++ 14
。还有 -std = c ++ 1y
和 -std = c ++ 17
。我总是得到这个:
main.cpp:8:44:error:'detected_or_t'在命名空间'std :: experimental'中没有命名模板类型
这些特征首先添加到GCC 6.1.0中的libstdc ++中,在 GCC 6发行说明中:
- 对第二版图书馆基础TS中大多数功能的实验性支持。
手册中的执行状态表,位于
https://gcc.gnu.org/onlinedocs /gcc-6.1.0/libstdc++/manual/manual/status.html#table.cxx1z_ts_status
我对libc ++不太确定,不支持铿锵3.9.1中的版本,但受当前主干支持,所以我认为它们首次出现在Clang 4.0.0中。
I am trying to use std::experimental::detect_or_t
from <experimental/type_traits>
.
What 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's difference_type should be int!");
static_assert(std::is_same<difference_type<Purr>, std::ptrdiff_t>::value, "Purr's 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 this:
main.cpp:8:44: error: 'detected_or_t' in namespace 'std::experimental' does not name a template type
Those traits were first added to libstdc++ in GCC 6.1.0, as documented in the GCC 6 release notes:
- Experimental support for most features of the second version of the Library Fundamentals TS.
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 less sure about libc++, but they're not supported by the version in Clang 3.9.1 but are supported by the current trunk, so I think they first appeared in Clang 4.0.0
这篇关于我需要使用什么编译器选项/库来使用detect_or_t类型特征?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!