2016-04-05 4 views
1

std::experimental::detect_or_t<experimental/type_traits>から使用しようとしています。detect_or_t型の特性を使用するためにはどのコンパイラオプション/ライブラリが必要ですか?

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!"); 
} 

私はclang++ -std=c++14g++ -std=c++14を使用してみました。また、-std=c++1yおよび-std=c++17である。私はいつもこれを取得:GCC 6 release notesに記載されているように

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

+5

GCC 6で動作するようだ。http://gcc.godbolt.org – melak47

+1

@ melak47、検証済みhttps://godbolt.org/で試してみる。 g/1tOlXq – alfC

+1

これはGithubで[libC++](https://github.com/llvm-mirror/libcxx)と[libstdC++]の両方で追跡できますhttps://github.com/gcc-mirror/gcc/tree/master/libstdc%2B%2B-v3)。後者ではサポートされていますが、前者ではサポートされていません。 – TemplateRex

答えて

1

これらの特徴は、まず、GCC 6.1.0で++のlibstdcに追加されました:第二版のほとんどの機能のための

  • 実験的サポート図書館の基礎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

関連する問題