algo: Added tests for mutable functor

This commit is contained in:
Kohei Takahashi
2018-07-03 00:48:40 +09:00
parent 0e4c5127f5
commit c1fe4e78ab
6 changed files with 122 additions and 25 deletions

View File

@ -1,19 +1,16 @@
/*=============================================================================
Copyright (c) 2001-2011 Joel de Guzman
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/adapted/mpl.hpp>
#include <boost/fusion/container/generation/make_vector.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/sequence/comparison/equal_to.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/container/generation/make_vector.hpp>
#include <boost/fusion/algorithm/transformation/replace_if.hpp>
#include <string>
struct gt3
{
@ -24,6 +21,15 @@ struct gt3
}
};
struct mutable_gt3 : gt3
{
template <typename T>
bool operator()(T x)
{
return gt3::operator()(x);
}
};
int
main()
{
@ -42,8 +48,18 @@ main()
{
std::cout << replace_if(t1, gt3(), -456) << std::endl;
BOOST_TEST((replace_if(t1, gt3(), -456)
== make_vector(1, 2, -456, -456, s, -456)));
BOOST_TEST_EQ(replace_if(t1, gt3(), -456), make_vector(1, 2, -456, -456, s, -456));
}
}
{
char const* s = "Ruby";
typedef vector<int, short, double, long, char const*, float> vector_type;
vector_type t1(1, 2, 3.3, 4, s, 5.5f);
{
std::cout << replace_if(t1, mutable_gt3(), -456) << std::endl;
BOOST_TEST_EQ(replace_if(t1, mutable_gt3(), -456), make_vector(1, 2, -456, -456, s, -456));
}
}