File indexing completed on 2025-12-16 10:09:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_TEST_TOOLS_DETAIL_TOLERANCE_MANIP_HPP_012705GER
0016 #define BOOST_TEST_TOOLS_DETAIL_TOLERANCE_MANIP_HPP_012705GER
0017
0018
0019 #include <boost/test/tools/detail/fwd.hpp>
0020 #include <boost/test/tools/detail/indirections.hpp>
0021
0022 #include <boost/test/utils/lazy_ostream.hpp>
0023 #include <boost/test/tools/fpc_tolerance.hpp>
0024 #include <boost/test/tools/floating_point_comparison.hpp>
0025
0026 #include <ostream>
0027
0028 #include <boost/test/detail/suppress_warnings.hpp>
0029
0030
0031
0032 namespace boost {
0033 namespace test_tools {
0034 namespace tt_detail {
0035
0036
0037
0038
0039
0040
0041
0042 template<typename FPT>
0043 struct tolerance_manip {
0044 explicit tolerance_manip( FPT const & tol ) : m_value( tol ) {}
0045
0046 FPT m_value;
0047 };
0048
0049
0050
0051 struct tolerance_manip_delay {};
0052
0053 template<typename FPT>
0054 inline tolerance_manip<FPT>
0055 operator%( FPT v, tolerance_manip_delay const& )
0056 {
0057 BOOST_STATIC_ASSERT_MSG( (fpc::tolerance_based<FPT>::value),
0058 "tolerance should be specified using a floating points type" );
0059
0060 return tolerance_manip<FPT>( FPT(v / 100) );
0061 }
0062
0063 template <typename FPT>
0064 struct tolerance_evaluation_context: assertion_evaluation_context {
0065 tolerance_evaluation_context(FPT tol)
0066 : assertion_evaluation_context( true )
0067 , m_tolerance_context(tol)
0068 {}
0069
0070 local_fpc_tolerance<FPT> m_tolerance_context;
0071 };
0072
0073
0074
0075 template<typename E, typename FPT>
0076 inline assertion_evaluate_t<E>
0077 operator<<(assertion_evaluate_t<E> const& ae, tolerance_manip<FPT> const& tol)
0078 {
0079 return ae.stack_context(
0080 typename assertion_evaluate_t<E>::context_holder(
0081 new tolerance_evaluation_context<FPT>( tol.m_value ))
0082 );
0083 }
0084
0085
0086
0087 template<typename FPT>
0088 unit_test::lazy_ostream &
0089 operator<<( unit_test::lazy_ostream &o, tolerance_manip<FPT> const& ) { return o; }
0090
0091
0092 template<typename FPT>
0093 std::ostream&
0094 operator<<( std::ostream& o, tolerance_manip<FPT> const& ) { return o; }
0095
0096
0097
0098
0099 template<typename FPT>
0100 inline assertion_type
0101 operator<<( assertion_type const& , tolerance_manip<FPT> const& ) {
0102 return assertion_type(CHECK_BUILT_ASSERTION);
0103 }
0104
0105
0106
0107 }
0108
0109
0110
0111
0112
0113
0114
0115 template<typename FPT>
0116 inline tt_detail::tolerance_manip<FPT>
0117 tolerance( FPT v )
0118 {
0119 BOOST_STATIC_ASSERT_MSG( (fpc::tolerance_based<FPT>::value),
0120 "tolerance only for floating points" );
0121
0122 return tt_detail::tolerance_manip<FPT>( v );
0123 }
0124
0125
0126
0127
0128 template<typename FPT>
0129 inline tt_detail::tolerance_manip<FPT>
0130 tolerance( fpc::percent_tolerance_t<FPT> v )
0131 {
0132 BOOST_STATIC_ASSERT_MSG( (fpc::tolerance_based<FPT>::value),
0133 "tolerance only for floating points" );
0134
0135 return tt_detail::tolerance_manip<FPT>( static_cast<FPT>(v.m_value / 100) );
0136 }
0137
0138
0139
0140
0141 inline tt_detail::tolerance_manip_delay
0142 tolerance()
0143 {
0144 return tt_detail::tolerance_manip_delay();
0145 }
0146
0147
0148
0149 }
0150 }
0151
0152 #include <boost/test/detail/enable_warnings.hpp>
0153
0154 #endif