1 #ifndef BOOST_METAPARSE_V1_CPP11_IMPL_NTH_OF_C_HPP 2 #define BOOST_METAPARSE_V1_CPP11_IMPL_NTH_OF_C_HPP 3 4 // Copyright Abel Sinkovics (abel@sinkovics.hu) 2017. 5 // Distributed under the Boost Software License, Version 1.0. 6 // (See accompanying file LICENSE_1_0.txt or copy at 7 // http://www.boost.org/LICENSE_1_0.txt) 8 9 #include <boost/metaparse/v1/cpp11/impl/nth_of_c_skip_remaining.hpp> 10 11 #include <boost/metaparse/v1/is_error.hpp> 12 #include <boost/metaparse/v1/get_remaining.hpp> 13 #include <boost/metaparse/v1/get_position.hpp> 14 #include <boost/metaparse/v1/get_result.hpp> 15 16 #include <type_traits> 17 18 namespace boost 19 { 20 namespace metaparse 21 { 22 namespace v1 23 { 24 namespace impl 25 { 26 template <int N, class S, class Pos, class... Ps> 27 struct nth_of_c; 28 29 template <int N, class S, class Pos, class P, class... Ps> 30 struct nth_of_c<N, S, Pos, P, Ps...> 31 { 32 private: 33 template <class NextResult> 34 struct apply_unchecked : 35 nth_of_c< 36 N - 1, 37 typename get_remaining<NextResult>::type, 38 typename get_position<NextResult>::type, 39 Ps... 40 > 41 {}; 42 43 public: 44 typedef 45 typename std::conditional< 46 is_error<typename P::template apply<S, Pos>>::type::value, 47 typename P::template apply<S, Pos>, 48 apply_unchecked<typename P::template apply<S, Pos>> 49 >::type::type 50 type; 51 }; 52 53 template <class P, class S, class Pos, class... Ps> 54 struct nth_of_c<0, S, Pos, P, Ps...> 55 { 56 private: 57 template <class NextResult> 58 struct apply_unchecked : 59 nth_of_c_skip_remaining< 60 typename get_result<NextResult>::type, 61 typename get_remaining<NextResult>::type, 62 typename get_position<NextResult>::type, 63 Ps... 64 > 65 {}; 66 67 public: 68 typedef 69 typename std::conditional< 70 is_error<typename P::template apply<S, Pos>>::type::value, 71 typename P::template apply<S, Pos>, 72 apply_unchecked<typename P::template apply<S, Pos>> 73 >::type::type 74 type; 75 }; 76 } 77 } 78 } 79 } 80 81 #endif 82 83