optional.hpp 930 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef BOOST_METAPARSE_V1_OPTIONAL_HPP
  2. #define BOOST_METAPARSE_V1_OPTIONAL_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2015.
  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/is_error.hpp>
  8. #include <boost/metaparse/v1/accept.hpp>
  9. #include <boost/mpl/if.hpp>
  10. namespace boost
  11. {
  12. namespace metaparse
  13. {
  14. namespace v1
  15. {
  16. template <class P, class Default = void>
  17. struct optional
  18. {
  19. typedef optional type;
  20. template <class S, class Pos>
  21. struct apply :
  22. boost::mpl::if_<
  23. is_error<typename P::template apply<S, Pos> >,
  24. accept<Default, S, Pos>,
  25. // is_error evaluates it anyway
  26. typename P::template apply<S, Pos>::type
  27. >
  28. {};
  29. };
  30. }
  31. }
  32. }
  33. #endif