nth_of_c.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef BOOST_METAPARSE_V1_CPP11_NTH_OF_C_HPP
  2. #define BOOST_METAPARSE_V1_CPP11_NTH_OF_C_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2017.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include <boost/metaparse/v1/cpp11/impl/nth_of_c.hpp>
  8. #include <boost/metaparse/v1/fail.hpp>
  9. #include <boost/metaparse/v1/error/index_out_of_range.hpp>
  10. #include <type_traits>
  11. namespace boost
  12. {
  13. namespace metaparse
  14. {
  15. namespace v1
  16. {
  17. template <int N, class... Ps>
  18. struct nth_of_c
  19. {
  20. typedef nth_of_c type;
  21. template <class S, class Pos>
  22. struct apply :
  23. std::conditional<
  24. (0 <= N && N < sizeof...(Ps)),
  25. impl::nth_of_c<N, S, Pos, Ps...>,
  26. typename fail<error::index_out_of_range<0, sizeof...(Ps) - 1, N>>
  27. ::template apply<S, Pos>
  28. >::type
  29. {};
  30. };
  31. template <int N>
  32. struct nth_of_c<N> : fail<error::index_out_of_range<0, -1, N>> {};
  33. }
  34. }
  35. }
  36. #endif