Eliminate warnings from BinaryFunction, UnaryPredicate, BinaryPredicate concept check classes.

[SVN r67422]
This commit is contained in:
Neil Groves
2010-12-23 00:43:10 +00:00
parent f81493caa1
commit b4ff615db8

View File

@ -38,14 +38,14 @@ namespace boost
// //
// Backward compatibility // Backward compatibility
// //
template <class Model> template <class Model>
inline void function_requires(Model* = 0) inline void function_requires(Model* = 0)
{ {
BOOST_CONCEPT_ASSERT((Model)); BOOST_CONCEPT_ASSERT((Model));
} }
template <class T> inline void ignore_unused_variable_warning(T const&) {} template <class T> inline void ignore_unused_variable_warning(T const&) {}
# define BOOST_CLASS_REQUIRE(type_var, ns, concept) \ # define BOOST_CLASS_REQUIRE(type_var, ns, concept) \
BOOST_CONCEPT_ASSERT((ns::concept<type_var>)) BOOST_CONCEPT_ASSERT((ns::concept<type_var>))
@ -58,14 +58,14 @@ namespace boost
# define BOOST_CLASS_REQUIRE4(tv1, tv2, tv3, tv4, ns, concept) \ # define BOOST_CLASS_REQUIRE4(tv1, tv2, tv3, tv4, ns, concept) \
BOOST_CONCEPT_ASSERT((ns::concept<tv1,tv2,tv3,tv4>)) BOOST_CONCEPT_ASSERT((ns::concept<tv1,tv2,tv3,tv4>))
// //
// Begin concept definitions // Begin concept definitions
// //
BOOST_concept(Integer, (T)) BOOST_concept(Integer, (T))
{ {
BOOST_CONCEPT_USAGE(Integer) BOOST_CONCEPT_USAGE(Integer)
{ {
x.error_type_must_be_an_integer_type(); x.error_type_must_be_an_integer_type();
} }
private: private:
@ -90,7 +90,7 @@ namespace boost
# endif # endif
BOOST_concept(SignedInteger,(T)) { BOOST_concept(SignedInteger,(T)) {
BOOST_CONCEPT_USAGE(SignedInteger) { BOOST_CONCEPT_USAGE(SignedInteger) {
x.error_type_must_be_a_signed_integer_type(); x.error_type_must_be_a_signed_integer_type();
} }
private: private:
@ -104,16 +104,16 @@ namespace boost
template <> struct SignedInteger< ::boost::long_long_type> {}; template <> struct SignedInteger< ::boost::long_long_type> {};
# elif defined(BOOST_HAS_MS_INT64) # elif defined(BOOST_HAS_MS_INT64)
template <> struct SignedInteger<__int64> {}; template <> struct SignedInteger<__int64> {};
# endif # endif
BOOST_concept(UnsignedInteger,(T)) { BOOST_concept(UnsignedInteger,(T)) {
BOOST_CONCEPT_USAGE(UnsignedInteger) { BOOST_CONCEPT_USAGE(UnsignedInteger) {
x.error_type_must_be_an_unsigned_integer_type(); x.error_type_must_be_an_unsigned_integer_type();
} }
private: private:
T x; T x;
}; };
template <> struct UnsignedInteger<unsigned char> {}; template <> struct UnsignedInteger<unsigned char> {};
template <> struct UnsignedInteger<unsigned short> {}; template <> struct UnsignedInteger<unsigned short> {};
template <> struct UnsignedInteger<unsigned int> {}; template <> struct UnsignedInteger<unsigned int> {};
@ -155,7 +155,7 @@ namespace boost
TT a; TT a;
}; };
BOOST_concept(CopyConstructible,(TT)) BOOST_concept(CopyConstructible,(TT))
{ {
BOOST_CONCEPT_USAGE(CopyConstructible) { BOOST_CONCEPT_USAGE(CopyConstructible) {
@ -300,7 +300,7 @@ namespace boost
BOOST_concept(Generator,(Func)(Return)) BOOST_concept(Generator,(Func)(Return))
{ {
BOOST_CONCEPT_USAGE(Generator) { test(is_void<Return>()); } BOOST_CONCEPT_USAGE(Generator) { test(is_void<Return>()); }
private: private:
void test(boost::mpl::false_) void test(boost::mpl::false_)
{ {
@ -313,22 +313,22 @@ namespace boost
{ {
f(); f();
} }
Func f; Func f;
}; };
BOOST_concept(UnaryFunction,(Func)(Return)(Arg)) BOOST_concept(UnaryFunction,(Func)(Return)(Arg))
{ {
BOOST_CONCEPT_USAGE(UnaryFunction) { test(is_void<Return>()); } BOOST_CONCEPT_USAGE(UnaryFunction) { test(is_void<Return>()); }
private: private:
void test(boost::mpl::false_) void test(boost::mpl::false_)
{ {
f(arg); // "priming the pump" this way keeps msvc6 happy (ICE) f(arg); // "priming the pump" this way keeps msvc6 happy (ICE)
Return r = f(arg); Return r = f(arg);
ignore_unused_variable_warning(r); ignore_unused_variable_warning(r);
} }
void test(boost::mpl::true_) void test(boost::mpl::true_)
{ {
f(arg); f(arg);
@ -357,12 +357,21 @@ namespace boost
Return r = f(first, second); // require operator() Return r = f(first, second); // require operator()
(void)r; (void)r;
} }
void test(boost::mpl::true_) void test(boost::mpl::true_)
{ {
f(first,second); f(first,second);
} }
#if (BOOST_WORKAROUND(__GNUC__, BOOST_TESTED_AT(4) \
&& BOOST_WORKAROUND(__GNUC__, > 3)))
// Declare a dummy constructor to make gcc happy.
// It seems the compiler can not generate a sensible constructor when this is instantiated with a refence type.
// (warning: non-static reference "const double& boost::BinaryFunction<YourClassHere>::arg"
// in class without a constructor [-Wuninitialized])
BinaryFunction();
#endif
Func f; Func f;
First first; First first;
Second second; Second second;
@ -374,6 +383,15 @@ namespace boost
require_boolean_expr(f(arg)); // require operator() returning bool require_boolean_expr(f(arg)); // require operator() returning bool
} }
private: private:
#if (BOOST_WORKAROUND(__GNUC__, BOOST_TESTED_AT(4) \
&& BOOST_WORKAROUND(__GNUC__, > 3)))
// Declare a dummy constructor to make gcc happy.
// It seems the compiler can not generate a sensible constructor when this is instantiated with a refence type.
// (warning: non-static reference "const double& boost::UnaryPredicate<YourClassHere>::arg"
// in class without a constructor [-Wuninitialized])
UnaryPredicate();
#endif
Func f; Func f;
Arg arg; Arg arg;
}; };
@ -384,6 +402,14 @@ namespace boost
require_boolean_expr(f(a, b)); // require operator() returning bool require_boolean_expr(f(a, b)); // require operator() returning bool
} }
private: private:
#if (BOOST_WORKAROUND(__GNUC__, BOOST_TESTED_AT(4) \
&& BOOST_WORKAROUND(__GNUC__, > 3)))
// Declare a dummy constructor to make gcc happy.
// It seems the compiler can not generate a sensible constructor when this is instantiated with a refence type.
// (warning: non-static reference "const double& boost::BinaryPredicate<YourClassHere>::arg"
// in class without a constructor [-Wuninitialized])
BinaryPredicate();
#endif
Func f; Func f;
First a; First a;
Second b; Second b;
@ -393,7 +419,7 @@ namespace boost
BOOST_concept(Const_BinaryPredicate,(Func)(First)(Second)) BOOST_concept(Const_BinaryPredicate,(Func)(First)(Second))
: BinaryPredicate<Func, First, Second> : BinaryPredicate<Func, First, Second>
{ {
BOOST_CONCEPT_USAGE(Const_BinaryPredicate) { BOOST_CONCEPT_USAGE(Const_BinaryPredicate) {
const_constraints(f); const_constraints(f);
} }
private: private:
@ -401,6 +427,15 @@ namespace boost
// operator() must be a const member function // operator() must be a const member function
require_boolean_expr(fun(a, b)); require_boolean_expr(fun(a, b));
} }
#if (BOOST_WORKAROUND(__GNUC__, BOOST_TESTED_AT(4) \
&& BOOST_WORKAROUND(__GNUC__, > 3)))
// Declare a dummy constructor to make gcc happy.
// It seems the compiler can not generate a sensible constructor when this is instantiated with a refence type.
// (warning: non-static reference "const double& boost::Const_BinaryPredicate<YourClassHere>::arg"
// in class without a constructor [-Wuninitialized])
Const_BinaryPredicate();
#endif
Func f; Func f;
First a; First a;
Second b; Second b;
@ -410,7 +445,7 @@ namespace boost
: Generator<Func, typename Func::result_type> : Generator<Func, typename Func::result_type>
{ {
typedef typename Func::result_type result_type; typedef typename Func::result_type result_type;
BOOST_CONCEPT_USAGE(AdaptableGenerator) BOOST_CONCEPT_USAGE(AdaptableGenerator)
{ {
BOOST_CONCEPT_ASSERT((Convertible<result_type, Return>)); BOOST_CONCEPT_ASSERT((Convertible<result_type, Return>));
@ -441,7 +476,7 @@ namespace boost
typedef typename Func::first_argument_type first_argument_type; typedef typename Func::first_argument_type first_argument_type;
typedef typename Func::second_argument_type second_argument_type; typedef typename Func::second_argument_type second_argument_type;
typedef typename Func::result_type result_type; typedef typename Func::result_type result_type;
~AdaptableBinaryFunction() ~AdaptableBinaryFunction()
{ {
BOOST_CONCEPT_ASSERT((Convertible<result_type, Return>)); BOOST_CONCEPT_ASSERT((Convertible<result_type, Return>));
@ -479,7 +514,7 @@ namespace boost
{ {
BOOST_CONCEPT_ASSERT((SignedInteger<difference_type>)); BOOST_CONCEPT_ASSERT((SignedInteger<difference_type>));
BOOST_CONCEPT_ASSERT((Convertible<iterator_category, std::input_iterator_tag>)); BOOST_CONCEPT_ASSERT((Convertible<iterator_category, std::input_iterator_tag>));
TT j(i); TT j(i);
(void)*i; // require dereference operator (void)*i; // require dereference operator
++j; // require preincrement operator ++j; // require preincrement operator
@ -493,7 +528,7 @@ namespace boost
: Assignable<TT> : Assignable<TT>
{ {
BOOST_CONCEPT_USAGE(OutputIterator) { BOOST_CONCEPT_USAGE(OutputIterator) {
++i; // require preincrement operator ++i; // require preincrement operator
i++; // require postincrement operator i++; // require postincrement operator
*i++ = t; // require postincrement and assignment *i++ = t; // require postincrement and assignment
@ -512,11 +547,11 @@ namespace boost
BOOST_DEDUCED_TYPENAME ForwardIterator::iterator_category BOOST_DEDUCED_TYPENAME ForwardIterator::iterator_category
, std::forward_iterator_tag , std::forward_iterator_tag
>)); >));
typename InputIterator<TT>::reference r = *i; typename InputIterator<TT>::reference r = *i;
ignore_unused_variable_warning(r); ignore_unused_variable_warning(r);
} }
private: private:
TT i; TT i;
}; };
@ -578,7 +613,7 @@ namespace boost
n = i - j; // require difference operator n = i - j; // require difference operator
(void)i[n]; // require element access operator (void)i[n]; // require element access operator
} }
private: private:
TT a, b; TT a, b;
TT i, j; TT i, j;
@ -616,7 +651,7 @@ namespace boost
BOOST_CONCEPT_ASSERT((InputIterator<const_iterator>)); BOOST_CONCEPT_ASSERT((InputIterator<const_iterator>));
const_constraints(c); const_constraints(c);
} }
private: private:
void const_constraints(const C& cc) { void const_constraints(const C& cc) {
i = cc.begin(); i = cc.begin();
@ -637,19 +672,19 @@ namespace boost
typedef typename C::reference reference; typedef typename C::reference reference;
typedef typename C::iterator iterator; typedef typename C::iterator iterator;
typedef typename C::pointer pointer; typedef typename C::pointer pointer;
BOOST_CONCEPT_USAGE(Mutable_Container) BOOST_CONCEPT_USAGE(Mutable_Container)
{ {
BOOST_CONCEPT_ASSERT(( BOOST_CONCEPT_ASSERT((
Assignable<typename Mutable_Container::value_type>)); Assignable<typename Mutable_Container::value_type>));
BOOST_CONCEPT_ASSERT((InputIterator<iterator>)); BOOST_CONCEPT_ASSERT((InputIterator<iterator>));
i = c.begin(); i = c.begin();
i = c.end(); i = c.end();
c.swap(c2); c.swap(c2);
} }
private: private:
iterator i; iterator i;
C c, c2; C c, c2;
@ -665,7 +700,7 @@ namespace boost
typename ForwardContainer::const_iterator typename ForwardContainer::const_iterator
>)); >));
} }
}; };
BOOST_concept(Mutable_ForwardContainer,(C)) BOOST_concept(Mutable_ForwardContainer,(C))
: ForwardContainer<C> : ForwardContainer<C>
@ -678,7 +713,7 @@ namespace boost
typename Mutable_ForwardContainer::iterator typename Mutable_ForwardContainer::iterator
>)); >));
} }
}; };
BOOST_concept(ReversibleContainer,(C)) BOOST_concept(ReversibleContainer,(C))
: ForwardContainer<C> : ForwardContainer<C>
@ -692,9 +727,9 @@ namespace boost
BOOST_CONCEPT_ASSERT(( BOOST_CONCEPT_ASSERT((
BidirectionalIterator< BidirectionalIterator<
typename ReversibleContainer::const_iterator>)); typename ReversibleContainer::const_iterator>));
BOOST_CONCEPT_ASSERT((BidirectionalIterator<const_reverse_iterator>)); BOOST_CONCEPT_ASSERT((BidirectionalIterator<const_reverse_iterator>));
const_constraints(c); const_constraints(c);
} }
private: private:
@ -711,17 +746,17 @@ namespace boost
, ReversibleContainer<C> , ReversibleContainer<C>
{ {
typedef typename C::reverse_iterator reverse_iterator; typedef typename C::reverse_iterator reverse_iterator;
BOOST_CONCEPT_USAGE(Mutable_ReversibleContainer) BOOST_CONCEPT_USAGE(Mutable_ReversibleContainer)
{ {
typedef typename Mutable_ForwardContainer<C>::iterator iterator; typedef typename Mutable_ForwardContainer<C>::iterator iterator;
BOOST_CONCEPT_ASSERT((Mutable_BidirectionalIterator<iterator>)); BOOST_CONCEPT_ASSERT((Mutable_BidirectionalIterator<iterator>));
BOOST_CONCEPT_ASSERT((Mutable_BidirectionalIterator<reverse_iterator>)); BOOST_CONCEPT_ASSERT((Mutable_BidirectionalIterator<reverse_iterator>));
reverse_iterator i = c.rbegin(); reverse_iterator i = c.rbegin();
i = c.rend(); i = c.rend();
} }
private: private:
C c; C c;
}; };
@ -737,7 +772,7 @@ namespace boost
RandomAccessIterator< RandomAccessIterator<
typename RandomAccessContainer::const_iterator typename RandomAccessContainer::const_iterator
>)); >));
const_constraints(c); const_constraints(c);
} }
private: private:
@ -746,7 +781,7 @@ namespace boost
const_reference r = cc[n]; const_reference r = cc[n];
ignore_unused_variable_warning(r); ignore_unused_variable_warning(r);
} }
C c; C c;
size_type n; size_type n;
}; };
@ -762,11 +797,11 @@ namespace boost
{ {
BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<typename self::iterator>)); BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<typename self::iterator>));
BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<typename self::reverse_iterator>)); BOOST_CONCEPT_ASSERT((Mutable_RandomAccessIterator<typename self::reverse_iterator>));
typename self::reference r = c[i]; typename self::reference r = c[i];
ignore_unused_variable_warning(r); ignore_unused_variable_warning(r);
} }
private: private:
typename Mutable_ReversibleContainer<C>::size_type i; typename Mutable_ReversibleContainer<C>::size_type i;
C c; C c;
@ -782,7 +817,7 @@ namespace boost
{ {
BOOST_CONCEPT_USAGE(Sequence) BOOST_CONCEPT_USAGE(Sequence)
{ {
S S
c(n), c(n),
c2(n, t), c2(n, t),
c3(first, last); c3(first, last);
@ -807,7 +842,7 @@ namespace boost
typename Sequence::const_reference r = c.front(); typename Sequence::const_reference r = c.front();
ignore_unused_variable_warning(r); ignore_unused_variable_warning(r);
} }
typename S::value_type t; typename S::value_type t;
typename S::size_type n; typename S::size_type n;
typename S::value_type* first, *last; typename S::value_type* first, *last;
@ -866,11 +901,11 @@ namespace boost
c.erase(r.first, r.second); c.erase(r.first, r.second);
const_constraints(c); const_constraints(c);
BOOST_CONCEPT_ASSERT((BinaryPredicate<key_compare,key_type,key_type>)); BOOST_CONCEPT_ASSERT((BinaryPredicate<key_compare,key_type,key_type>));
typedef typename AssociativeContainer::value_type value_type_; typedef typename AssociativeContainer::value_type value_type_;
BOOST_CONCEPT_ASSERT((BinaryPredicate<value_compare,value_type_,value_type_>)); BOOST_CONCEPT_ASSERT((BinaryPredicate<value_compare,value_type_,value_type_>));
} }
// Redundant with the base concept, but it helps below. // Redundant with the base concept, but it helps below.
typedef typename C::const_iterator const_iterator; typedef typename C::const_iterator const_iterator;
private: private:
@ -896,7 +931,7 @@ namespace boost
BOOST_CONCEPT_USAGE(UniqueAssociativeContainer) BOOST_CONCEPT_USAGE(UniqueAssociativeContainer)
{ {
C c(first, last); C c(first, last);
pos_flag = c.insert(t); pos_flag = c.insert(t);
c.insert(first, last); c.insert(first, last);
@ -914,7 +949,7 @@ namespace boost
BOOST_CONCEPT_USAGE(MultipleAssociativeContainer) BOOST_CONCEPT_USAGE(MultipleAssociativeContainer)
{ {
C c(first, last); C c(first, last);
pos = c.insert(t); pos = c.insert(t);
c.insert(first, last); c.insert(first, last);
@ -957,7 +992,7 @@ namespace boost
{ {
BOOST_CONCEPT_USAGE(SortedAssociativeContainer) BOOST_CONCEPT_USAGE(SortedAssociativeContainer)
{ {
C C
c(kc), c(kc),
c2(first, last), c2(first, last),
c3(first, last, kc); c3(first, last, kc);
@ -965,15 +1000,15 @@ namespace boost
p = c.upper_bound(k); p = c.upper_bound(k);
p = c.lower_bound(k); p = c.lower_bound(k);
r = c.equal_range(k); r = c.equal_range(k);
c.insert(p, t); c.insert(p, t);
ignore_unused_variable_warning(c); ignore_unused_variable_warning(c);
ignore_unused_variable_warning(c2); ignore_unused_variable_warning(c2);
ignore_unused_variable_warning(c3); ignore_unused_variable_warning(c3);
const_constraints(c); const_constraints(c);
} }
void const_constraints(const C& c) void const_constraints(const C& c)
{ {
kc = c.key_comp(); kc = c.key_comp();
@ -983,7 +1018,7 @@ namespace boost
cp = c.lower_bound(k); cp = c.lower_bound(k);
cr = c.equal_range(k); cr = c.equal_range(k);
} }
private: private:
typename C::key_compare kc; typename C::key_compare kc;
typename C::value_compare vc; typename C::value_compare vc;