fix doc example typo
[boost.git] / boost / test / predicate_result.hpp
blob8ac18b754b595c2d6dc02cd0a4f2976737f6697c
1 // (C) Copyright Gennadiy Rozental 2001-2008.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
7 //
8 // File : $RCSfile$
9 //
10 // Version : $Revision$
12 // Description : enhanced result for test predicate that include message explaining failure
13 // ***************************************************************************
15 #ifndef BOOST_TEST_PREDICATE_RESULT_HPP_012705GER
16 #define BOOST_TEST_PREDICATE_RESULT_HPP_012705GER
18 // Boost.Test
19 #include <boost/test/utils/class_properties.hpp>
20 #include <boost/test/utils/wrap_stringstream.hpp>
21 #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
23 // Boost
24 #include <boost/shared_ptr.hpp>
25 #include <boost/detail/workaround.hpp>
27 // STL
28 #include <cstddef> // for std::size_t
30 #include <boost/test/detail/suppress_warnings.hpp>
32 //____________________________________________________________________________//
34 namespace boost {
36 namespace test_tools {
38 // ************************************************************************** //
39 // ************** predicate_result ************** //
40 // ************************************************************************** //
42 class BOOST_TEST_DECL predicate_result {
43 typedef unit_test::const_string const_string;
44 struct dummy { void nonnull() {}; };
45 typedef void (dummy::*safe_bool)();
47 public:
48 // Constructor
49 predicate_result( bool pv_ )
50 : p_predicate_value( pv_ )
53 template<typename BoolConvertable>
54 predicate_result( BoolConvertable const& pv_ ) : p_predicate_value( !!pv_ ) {}
56 // Access methods
57 bool operator!() const { return !p_predicate_value; }
58 void operator=( bool pv_ ) { p_predicate_value.value = pv_; }
59 operator safe_bool() const { return !!p_predicate_value ? &dummy::nonnull : 0; }
61 // Public properties
62 BOOST_READONLY_PROPERTY( bool, (predicate_result) ) p_predicate_value;
64 // Access methods
65 bool has_empty_message() const { return !m_message; }
66 wrap_stringstream& message()
68 if( !m_message )
69 m_message.reset( new wrap_stringstream );
71 return *m_message;
73 const_string message() const { return !m_message ? const_string() : const_string( m_message->str() ); }
75 private:
76 // Data members
77 shared_ptr<wrap_stringstream> m_message;
80 } // namespace test_tools
82 } // namespace boost
84 //____________________________________________________________________________//
86 #include <boost/test/detail/enable_warnings.hpp>
88 #endif // BOOST_TEST_PREDICATE_RESULT_HPP_012705GER