| 1 | /*============================================================================= |
| 2 | Copyright (c) 2003 Joel de Guzman |
| 3 | http://spirit.sourceforge.net/ |
| 4 | |
| 5 | Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 6 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 7 | =============================================================================*/ |
| 8 | #if !defined(BOOST_SPIRIT_SAFE_BOOL_HPP) |
| 9 | #define BOOST_SPIRIT_SAFE_BOOL_HPP |
| 10 | |
| 11 | #include <boost/config.hpp> |
| 12 | #include <boost/detail/workaround.hpp> |
| 13 | #include <boost/spirit/home/classic/namespace.hpp> |
| 14 | |
| 15 | namespace boost { namespace spirit { |
| 16 | |
| 17 | BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN |
| 18 | |
| 19 | namespace impl |
| 20 | { |
| 21 | template <typename T> |
| 22 | struct no_base {}; |
| 23 | |
| 24 | template <typename T> |
| 25 | struct safe_bool_impl |
| 26 | { |
| 27 | #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) |
| 28 | void stub(T*) {}; |
| 29 | typedef void (safe_bool_impl::*type)(T*); |
| 30 | #else |
| 31 | typedef T* TP; // workaround to make parsing easier |
| 32 | TP stub; |
| 33 | typedef TP safe_bool_impl::*type; |
| 34 | #endif |
| 35 | }; |
| 36 | } |
| 37 | |
| 38 | template <typename DerivedT, typename BaseT = impl::no_base<DerivedT> > |
| 39 | struct safe_bool : BaseT |
| 40 | { |
| 41 | private: |
| 42 | typedef impl::safe_bool_impl<DerivedT> impl_t; |
| 43 | typedef typename impl_t::type bool_type; |
| 44 | |
| 45 | public: |
| 46 | operator bool_type() const |
| 47 | { |
| 48 | return static_cast<const DerivedT*>(this)->operator_bool() ? |
| 49 | &impl_t::stub : 0; |
| 50 | } |
| 51 | |
| 52 | operator bool_type() |
| 53 | { |
| 54 | return static_cast<DerivedT*>(this)->operator_bool() ? |
| 55 | &impl_t::stub : 0; |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | BOOST_SPIRIT_CLASSIC_NAMESPACE_END |
| 60 | |
| 61 | }} |
| 62 | |
| 63 | #endif |
| 64 | |
| 65 | |