forked from boostorg/fusion
algo: Added tests for mutable functor
This commit is contained in:
@ -1,11 +1,12 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2011 Joel de Guzman
|
||||
Copyright (c) 2007 Dan Marsden
|
||||
Copyright (c) 2018 Kohei Takahashi
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/adapted/mpl.hpp>
|
||||
#include <boost/fusion/algorithm/query/all.hpp>
|
||||
@ -28,6 +29,19 @@ namespace
|
||||
|
||||
int search;
|
||||
};
|
||||
|
||||
struct mutable_search_for : search_for
|
||||
{
|
||||
explicit mutable_search_for(int in_search)
|
||||
: search_for(in_search)
|
||||
{}
|
||||
|
||||
template <typename T>
|
||||
bool operator()(T const& v)
|
||||
{
|
||||
return search_for::operator()(v);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
int
|
||||
@ -58,11 +72,20 @@ main()
|
||||
}
|
||||
|
||||
{
|
||||
typedef boost::mpl::vector_c<int, 1> mpl_vec;
|
||||
boost::fusion::vector<int, short, double> t(1, 2, 3.3);
|
||||
BOOST_TEST(!boost::fusion::all(t, search_for(1)));
|
||||
BOOST_TEST(!boost::fusion::all(t, mutable_search_for(1)));
|
||||
}
|
||||
|
||||
{
|
||||
typedef boost::mpl::vector_c<int, 1, 1, 1> mpl_vec;
|
||||
// We cannot use lambda here as mpl vec iterators return
|
||||
// rvalues, and lambda needs lvalues.
|
||||
BOOST_TEST(boost::fusion::all(mpl_vec(), search_for(1)));
|
||||
BOOST_TEST(!boost::fusion::all(mpl_vec(), search_for(2)));
|
||||
|
||||
BOOST_TEST(boost::fusion::all(mpl_vec(), mutable_search_for(1)));
|
||||
BOOST_TEST(!boost::fusion::all(mpl_vec(), mutable_search_for(2)));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
|
Reference in New Issue
Block a user