1 #ifndef BOOST_METAPARSE_V1_ACCEPT_WHEN_HPP 2 #define BOOST_METAPARSE_V1_ACCEPT_WHEN_HPP 3 4 // Copyright Abel Sinkovics (abel@sinkovics.hu) 2009 - 2010. 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/get_result.hpp> 10 #include <boost/metaparse/v1/reject.hpp> 11 #include <boost/metaparse/v1/is_error.hpp> 12 13 #include <boost/mpl/if.hpp> 14 #include <boost/mpl/eval_if.hpp> 15 16 namespace boost 17 { 18 namespace metaparse 19 { 20 namespace v1 21 { 22 template <class P, class Pred, class Msg> 23 struct accept_when 24 { 25 private: 26 struct unchecked 27 { 28 template <class S, class Pos> 29 struct apply : 30 boost::mpl::eval_if< 31 typename Pred::template apply< 32 typename get_result<typename P::template apply<S, Pos> >::type 33 >::type, 34 typename P::template apply<S, Pos>, 35 reject<Msg, Pos> 36 > 37 {}; 38 }; 39 public: 40 typedef accept_when type; 41 42 template <class S, class Pos> 43 struct apply : 44 boost::mpl::if_< 45 is_error<typename P::template apply<S, Pos> >, 46 P, 47 unchecked 48 >::type::template apply< 49 S, 50 Pos 51 > 52 {}; 53 }; 54 } 55 } 56 } 57 58 #endif 59 60