fork(1) download
  1. #include <iterator>
  2. #include <type_traits>
  3. #include <vector>
  4.  
  5. template<typename T>
  6. struct iterated {
  7. using type = decltype(*std::begin(std::declval<T>()));
  8. };
  9.  
  10. using X = typename iterated<std::vector<int>>::type; // OK
  11. using Y = typename iterated<int[2]>::type; // FAILS
  12.  
  13. int main() {
  14. return 0;
  15. }
Compilation error #stdin compilation error #stdout 0s 3136KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'struct iterated<int [2]>':
prog.cpp:11:36:   required from here
prog.cpp:7:53: error: no matching function for call to 'begin(int [2])'
  using type = decltype(*std::begin(std::declval<T>()));
                                                     ^
prog.cpp:7:53: note: candidates are:
In file included from /usr/include/c++/4.9/string:51:0,
                 from /usr/include/c++/4.9/bits/locale_classes.h:40,
                 from /usr/include/c++/4.9/bits/ios_base.h:41,
                 from /usr/include/c++/4.9/ios:42,
                 from /usr/include/c++/4.9/ostream:38,
                 from /usr/include/c++/4.9/iterator:64,
                 from prog.cpp:1:
/usr/include/c++/4.9/bits/range_access.h:48:5: note: template<class _Container> decltype (__cont.begin()) std::begin(_Container&)
     begin(_Container& __cont) -> decltype(__cont.begin())
     ^
/usr/include/c++/4.9/bits/range_access.h:48:5: note:   template argument deduction/substitution failed:
/usr/include/c++/4.9/bits/range_access.h: In substitution of 'template<class _Container> decltype (__cont.begin()) std::begin(_Container&) [with _Container = int [2]]':
prog.cpp:7:53:   required from 'struct iterated<int [2]>'
prog.cpp:11:36:   required from here
/usr/include/c++/4.9/bits/range_access.h:48:5: error: request for member 'begin' in '__cont', which is of non-class type 'int [2]'
prog.cpp: In instantiation of 'struct iterated<int [2]>':
prog.cpp:11:36:   required from here
/usr/include/c++/4.9/bits/range_access.h:58:5: note: template<class _Container> decltype (__cont.begin()) std::begin(const _Container&)
     begin(const _Container& __cont) -> decltype(__cont.begin())
     ^
/usr/include/c++/4.9/bits/range_access.h:58:5: note:   template argument deduction/substitution failed:
/usr/include/c++/4.9/bits/range_access.h: In substitution of 'template<class _Container> decltype (__cont.begin()) std::begin(const _Container&) [with _Container = int [2]]':
prog.cpp:7:53:   required from 'struct iterated<int [2]>'
prog.cpp:11:36:   required from here
/usr/include/c++/4.9/bits/range_access.h:58:5: error: request for member 'begin' in '__cont', which is of non-class type 'const int [2]'
prog.cpp: In instantiation of 'struct iterated<int [2]>':
prog.cpp:11:36:   required from here
/usr/include/c++/4.9/bits/range_access.h:87:5: note: _Tp* std::begin(_Tp (&)[_Nm]) [with _Tp = int; unsigned int _Nm = 2u]
     begin(_Tp (&__arr)[_Nm])
     ^
/usr/include/c++/4.9/bits/range_access.h:87:5: note:   no known conversion for argument 1 from 'int [2]' to 'int (&)[2]'
In file included from /usr/include/c++/4.9/bits/basic_string.h:42:0,
                 from /usr/include/c++/4.9/string:52,
                 from /usr/include/c++/4.9/bits/locale_classes.h:40,
                 from /usr/include/c++/4.9/bits/ios_base.h:41,
                 from /usr/include/c++/4.9/ios:42,
                 from /usr/include/c++/4.9/ostream:38,
                 from /usr/include/c++/4.9/iterator:64,
                 from prog.cpp:1:
/usr/include/c++/4.9/initializer_list:89:5: note: template<class _Tp> constexpr const _Tp* std::begin(std::initializer_list<_Tp>)
     begin(initializer_list<_Tp> __ils) noexcept
     ^
/usr/include/c++/4.9/initializer_list:89:5: note:   template argument deduction/substitution failed:
prog.cpp:7:53: note:   mismatched types 'std::initializer_list<_Tp>' and 'int*'
  using type = decltype(*std::begin(std::declval<T>()));
                                                     ^
prog.cpp:11:38: error: invalid combination of multiple type-specifiers
 using Y = typename iterated<int[2]>::type; // FAILS
                                      ^
stdout
Standard output is empty