source: NonGTP/Boost/boost/spirit/core/safe_bool.hpp @ 857

Revision 857, 1.7 KB checked in by igarcia, 18 years ago (diff)
Line 
1/*=============================================================================
2    Copyright (c) 2003 Joel de Guzman
3    http://spirit.sourceforge.net/
4
5    Use, modification and distribution is subject to the Boost Software
6    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7    http://www.boost.org/LICENSE_1_0.txt)
8=============================================================================*/
9#if !defined(BOOST_SPIRIT_SAFE_BOOL_HPP)
10#define BOOST_SPIRIT_SAFE_BOOL_HPP
11
12#include <boost/config.hpp>
13#include <boost/detail/workaround.hpp>
14
15namespace boost { namespace spirit
16{
17    namespace impl
18    {
19        template <typename T>
20        struct no_base {};
21
22        template <typename T>
23        struct safe_bool_impl
24        {
25#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
26            void stub(T*) {};
27            typedef void (safe_bool_impl::*type)(T*);
28#else
29            typedef T* TP; // workaround to make parsing easier
30            TP stub;
31            typedef TP safe_bool_impl::*type;
32#endif
33        };
34    }
35
36    template <typename DerivedT, typename BaseT = impl::no_base<DerivedT> >
37    struct safe_bool : BaseT
38    {
39    private:
40        typedef impl::safe_bool_impl<DerivedT> impl_t;
41        typedef typename impl_t::type bool_type;
42
43    public:
44        operator bool_type() const
45        {
46            return static_cast<const DerivedT*>(this)->operator_bool() ?
47                &impl_t::stub : 0;
48        }
49
50        operator bool_type()
51        {
52            return static_cast<DerivedT*>(this)->operator_bool() ?
53                &impl_t::stub : 0;
54        }
55    };
56}}
57
58#endif
59
Note: See TracBrowser for help on using the repository browser.