[DEV] add v1.66.0

This commit is contained in:
2018-01-12 21:47:58 +01:00
parent 87059bb1af
commit a97e9ae7d4
49032 changed files with 7668950 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
# Copyright 2016-2017 Joaqu<71>n M L<>pez Mu<4D>oz.
# 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)
#
# See http://www.boost.org/libs/poly_collection for library home page.
import testing ;
import ../../config/checks/config : requires ;
project
: requirements
[ requires cxx11_noexcept ] # used as a proxy for C++11 support
<toolset>msvc:<cxxflags>-D_SCL_SECURE_NO_WARNINGS
;
test-suite "poly_collection" :
[ run test_algorithm.cpp test_algorithm1.cpp
test_algorithm2.cpp test_algorithm3.cpp
test_algorithm_main.cpp
:
:
: <toolset>msvc:<cxxflags>/bigobj
<toolset>gcc:<inlining>on
<toolset>gcc:<optimization>space
<toolset>clang:<inlining>on
<toolset>clang:<optimization>space ]
[ run test_capacity.cpp test_capacity_main.cpp ]
[ run test_comparison.cpp test_comparison_main.cpp ]
[ run test_construction.cpp test_construction_main.cpp
:
:
: <toolset>msvc:<cxxflags>/bigobj
<toolset>gcc:<inlining>on
<toolset>gcc:<optimization>space
<toolset>clang:<inlining>on
<toolset>clang:<optimization>space ]
[ run test_emplacement.cpp test_emplacement_main.cpp ]
[ run test_erasure.cpp test_erasure_main.cpp ]
[ run test_insertion.cpp test_insertion_main.cpp ]
[ run test_iterators.cpp test_iterators_main.cpp ]
[ run test_registration.cpp test_registration_main.cpp ]
;

View File

@@ -0,0 +1,96 @@
/* Copyright 2016-2017 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#ifndef BOOST_POLY_COLLECTION_TEST_ANY_TYPES_HPP
#define BOOST_POLY_COLLECTION_TEST_ANY_TYPES_HPP
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/mpl/vector/vector10.hpp>
#include <boost/poly_collection/any_collection.hpp>
#include <boost/type_erasure/any_cast.hpp>
#include <boost/type_erasure/builtin.hpp>
#include <boost/type_erasure/call.hpp>
#include <boost/type_erasure/operators.hpp>
namespace any_types{
struct incrementable1
{
incrementable1(int n):n{n}{}
incrementable1(incrementable1&&)=default;
incrementable1(const incrementable1&)=delete;
incrementable1& operator=(incrementable1&&)=default;
incrementable1& operator=(const incrementable1&)=delete;
bool operator==(const incrementable1& x)const{return n==x.n;}
incrementable1& operator++(){++n;return *this;}
int n;
};
struct incrementable3
{
incrementable3():n{-1}{}
incrementable3(int n):n{(double)n}{}
incrementable3& operator++(){++n;return *this;}
double n;
};
using concept_=boost::type_erasure::incrementable<>;
using collection=boost::any_collection<concept_>;
template<typename T=boost::type_erasure::_self>
struct convertible_to_int
{
static int apply(const T& x){return x;}
};
using t1=incrementable1;
using t2=double;
using t3=incrementable3;
using t4=int;
using t5=boost::type_erasure::any<
boost::mpl::vector4<
boost::type_erasure::copy_constructible<>,
boost::type_erasure::assignable<>,
concept_,
convertible_to_int<>
>
>;
struct to_int
{
to_int(){};
template<typename Concept,typename Tag>
int operator()(const boost::type_erasure::any<Concept,Tag>& x)const
{
using boost::type_erasure::any_cast;
if(auto p=any_cast<t1*>(&x))return (*this)(*p);
if(auto p=any_cast<t2*>(&x))return (*this)(*p);
if(auto p=any_cast<t3*>(&x))return (*this)(*p);
if(auto p=any_cast<t4*>(&x))return (*this)(*p);
if(auto p=any_cast<t5*>(&x))return (*this)(*p);
else return 0;
}
int operator()(const t1& x)const{return x.n;}
int operator()(const t2& x)const{return static_cast<int>(x);};
int operator()(const t3& x)const{return static_cast<int>(x.n);}
int operator()(const t4& x)const{return x;}
int operator()(const t5& x)const
{
return boost::type_erasure::call(convertible_to_int<>{},x);
}
};
} /* namespace any_types */
#endif

View File

@@ -0,0 +1,94 @@
/* Copyright 2016-2017 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#ifndef BOOST_POLY_COLLECTION_TEST_BASE_TYPES_HPP
#define BOOST_POLY_COLLECTION_TEST_BASE_TYPES_HPP
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/poly_collection/base_collection.hpp>
namespace base_types{
struct base
{
virtual ~base()=default;
virtual int operator()(int)const=0;
};
struct derived1 final:base
{
derived1(int n):n{n}{}
derived1(derived1&&)=default;
derived1(const derived1&)=delete;
derived1& operator=(derived1&&)=default;
derived1& operator=(const derived1&)=delete;
virtual int operator()(int)const{return n;}
bool operator==(const derived1& x)const{return n==x.n;}
int n;
};
struct derived2:base
{
derived2(int n):n{n}{}
derived2(derived2&&)=default;
derived2& operator=(derived2&&)=delete;
virtual int operator()(int x)const{return x*n;}
bool operator==(const derived2& x)const{return n==x.n;}
int n;
};
struct derived3:base
{
derived3():n{-1}{}
derived3(int n):n{n}{}
virtual int operator()(int x)const{return x*x*n;}
int n;
};
struct another_base
{
virtual ~another_base()=default;
char x[5];
};
struct derived4:another_base,derived3
{
using derived3::derived3;
virtual int operator()(int x)const{return -(this->derived3::operator()(x));}
bool operator==(const derived4& x)const{return n==x.n;}
};
struct derived5:base,another_base
{
derived5(int n):n{n}{}
virtual int operator()(int x)const{return x*x*x*n;}
int n;
};
using collection=boost::base_collection<base>;
using t1=derived1;
using t2=derived2;
using t3=derived3;
using t4=derived4;
using t5=derived5;
struct to_int
{
to_int(){};
template<typename F>
int operator()(const F& f)const{return f(1);}
};
} /* namespace base_types */
#endif

View File

@@ -0,0 +1,146 @@
/* Copyright 2016-2017 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#ifndef BOOST_POLY_COLLECTION_TEST_FUNCTION_TYPES_HPP
#define BOOST_POLY_COLLECTION_TEST_FUNCTION_TYPES_HPP
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/poly_collection/function_collection.hpp>
#include <typeinfo>
namespace function_types{
struct function1 final
{
function1(int n):n{n}{}
function1(function1&&)=default;
function1(const function1&)=delete;
function1& operator=(function1&&)=default;
function1& operator=(const function1&)=delete;
int operator()(int)const{return n;}
friend bool operator==(
const function1& x,const function1& y){return x.n==y.n;}
int n;
};
struct function2
{
function2(int n):n{n}{}
int operator()(int x)const{return x*n;}
bool operator==(const function2& x)const{return n==x.n;}
int n;
};
struct function3
{
function3():n{-1}{}
function3(int n):n{n}{}
int operator()(int x)const{return x*x*n;}
int n;
};
struct function4:function3
{
using function3::function3;
int operator()(int x)const{return -(this->function3::operator()(x));}
bool operator==(const function4& x)const{return n==x.n;}
};
struct function5
{
function5(int n):n{n}{}
int operator()(int x)const{return x*x*x*n;}
int n;
};
struct int_alias /* brings this namespace into ADL for operator== below */
{
int_alias(int n):n{n}{}
operator int()const{return n;}
int n;
};
using signature=int_alias(int);
using collection=boost::function_collection<signature>;
using t1=function1;
using t2=function2;
using t3=function3;
using t4=function4;
using t5=function5;
inline bool operator==(
const collection::value_type& x,const collection::value_type& y)
{
const std::type_info& xi=x.target_type();
const std::type_info& yi=y.target_type();
if(xi==yi){
if(xi==typeid(t1))return (*x.target<t1>())==(*y.target<t1>());
if(xi==typeid(t2))return (*x.target<t2>()).operator==(*y.target<t2>());
if(xi==typeid(t4))return (*x.target<t4>()).operator==(*y.target<t4>());
}
return false;
}
inline bool operator==(const collection::value_type& x,const t1& y)
{
const std::type_info& xi=x.target_type();
if(xi==typeid(t1))return (*x.target<t1>())==y;
return false;
}
inline bool operator==(const t1& x,const collection::value_type& y)
{
return y==x;
}
inline bool operator==(const collection::value_type& x,const t2& y)
{
const std::type_info& xi=x.target_type();
if(xi==typeid(t2))return (*x.target<t2>())==y;
return false;
}
inline bool operator==(const t2& x,const collection::value_type& y)
{
return y==x;
}
inline bool operator==(const collection::value_type& x,const t4& y)
{
const std::type_info& xi=x.target_type();
if(xi==typeid(t4))return (*x.target<t4>())==y;
return false;
}
inline bool operator==(const t4& x,const collection::value_type& y)
{
return y==x;
}
inline bool operator==(const t1&,const t2&){return false;}
inline bool operator==(const t1&,const t4&){return false;}
inline bool operator==(const t2&,const t1&){return false;}
inline bool operator==(const t2&,const t4&){return false;}
inline bool operator==(const t4&,const t1&){return false;}
inline bool operator==(const t4&,const t2&){return false;}
struct to_int
{
to_int(){};
template<typename F>
int operator()(const F& f)const{return f(1);}
};
} /* namespace function_types */
#endif

View File

@@ -0,0 +1,21 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include "test_algorithm.hpp"
#include "test_algorithm1.hpp"
#include "test_algorithm2.hpp"
#include "test_algorithm3.hpp"
/* test split in chunks to avoid problems with compilation object sizes */
void test_algorithm()
{
test_algorithm1();
test_algorithm2();
test_algorithm3();
}

View File

@@ -0,0 +1,9 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
void test_algorithm();

View File

@@ -0,0 +1,20 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include "test_algorithm1.hpp"
#include "any_types.hpp"
#include "test_algorithm_impl.hpp"
void test_algorithm1()
{
test_algorithm<
any_types::collection,jammed_auto_increment,any_types::to_int,
any_types::t1,any_types::t2,any_types::t3,
any_types::t4,any_types::t5>();
}

View File

@@ -0,0 +1,9 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
void test_algorithm1();

View File

@@ -0,0 +1,20 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include "test_algorithm2.hpp"
#include "base_types.hpp"
#include "test_algorithm_impl.hpp"
void test_algorithm2()
{
test_algorithm<
base_types::collection,jammed_auto_increment,base_types::to_int,
base_types::t1,base_types::t2,base_types::t3,
base_types::t4,base_types::t5>();
}

View File

@@ -0,0 +1,9 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
void test_algorithm2();

View File

@@ -0,0 +1,20 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include "test_algorithm3.hpp"
#include "function_types.hpp"
#include "test_algorithm_impl.hpp"
void test_algorithm3()
{
test_algorithm<
function_types::collection,jammed_auto_increment,function_types::to_int,
function_types::t1,function_types::t2,function_types::t3,
function_types::t4,function_types::t5>();
}

View File

@@ -0,0 +1,9 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
void test_algorithm3();

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,16 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include <boost/core/lightweight_test.hpp>
#include "test_algorithm.hpp"
int main()
{
test_algorithm();
return boost::report_errors();
}

View File

@@ -0,0 +1,33 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include <boost/core/lightweight_test.hpp>
#include "test_algorithm.hpp"
#include "test_capacity.hpp"
#include "test_comparison.hpp"
#include "test_construction.hpp"
#include "test_emplacement.hpp"
#include "test_erasure.hpp"
#include "test_insertion.hpp"
#include "test_iterators.hpp"
#include "test_registration.hpp"
int main()
{
test_algorithm();
test_capacity();
test_comparison();
test_construction();
test_emplacement();
test_erasure();
test_insertion();
test_iterators();
test_registration();
return boost::report_errors();
}

View File

@@ -0,0 +1,92 @@
/* Copyright 2016-2017 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include "test_capacity.hpp"
#include <algorithm>
#include <boost/core/lightweight_test.hpp>
#include "any_types.hpp"
#include "base_types.hpp"
#include "function_types.hpp"
#include "test_utilities.hpp"
using namespace test_utilities;
template<typename PolyCollection,typename ValueFactory,typename... Types>
void test_capacity()
{
PolyCollection p;
const PolyCollection& cp=p;
ValueFactory v;
BOOST_TEST(cp.empty());
BOOST_TEST(cp.size()==0);
p.template register_types<Types...>();
BOOST_TEST(cp.empty());
do_((BOOST_TEST(cp.empty(typeid(Types))),0)...);
do_((BOOST_TEST(cp.template empty<Types>()),0)...);
BOOST_TEST(cp.size()==0);
do_((BOOST_TEST(cp.size(typeid(Types))==0),0)...);
do_((BOOST_TEST(cp.template size<Types>()==0),0)...);
p.reserve(10);
do_((BOOST_TEST(cp.capacity(typeid(Types))>=10),0)...);
do_((BOOST_TEST(
cp.template capacity<Types>()==cp.capacity(typeid(Types))),0)...);
do_((p.reserve(typeid(Types),20),0)...);
do_((BOOST_TEST(cp.capacity(typeid(Types))>=20),0)...);
do_((p.template reserve<Types>(30),0)...);
do_((BOOST_TEST(cp.template capacity<Types>()>=30),0)...);
fill<constraints<>,Types...>(p,v,30);
BOOST_TEST(cp.size()==30*sizeof...(Types));
do_((BOOST_TEST(cp.size(typeid(Types))==30),0)...);
do_((BOOST_TEST(cp.template size<Types>()==cp.size(typeid(Types))),0)...);
auto min_capacity=[&]{
return (std::min)({cp.template capacity<Types>()...});
};
p.reserve(min_capacity()+1);
BOOST_TEST(cp.size()==30*sizeof...(Types));
auto c=min_capacity();
p.shrink_to_fit();
BOOST_TEST(c>=min_capacity());
c=min_capacity();
do_((p.erase(cp.template begin<Types>()),0)...);
BOOST_TEST(c==min_capacity());
do_((p.shrink_to_fit(typeid(Types)),0)...);
BOOST_TEST(c>=min_capacity());
c=min_capacity();
p.clear();
do_((p.template shrink_to_fit<Types>(),0)...);
BOOST_TEST(c>=min_capacity());
}
void test_capacity()
{
test_capacity<
any_types::collection,auto_increment,
any_types::t1,any_types::t2,any_types::t3,
any_types::t4,any_types::t5>();
test_capacity<
base_types::collection,auto_increment,
base_types::t1,base_types::t2,base_types::t3,
base_types::t4,base_types::t5>();
test_capacity<
function_types::collection,auto_increment,
function_types::t1,function_types::t2,function_types::t3,
function_types::t4,function_types::t5>();
}

View File

@@ -0,0 +1,9 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
void test_capacity();

View File

@@ -0,0 +1,16 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include <boost/core/lightweight_test.hpp>
#include "test_capacity.hpp"
int main()
{
test_capacity();
return boost::report_errors();
}

View File

@@ -0,0 +1,156 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include "test_comparison.hpp"
#include <boost/core/lightweight_test.hpp>
#include "any_types.hpp"
#include "base_types.hpp"
#include "function_types.hpp"
#include "test_utilities.hpp"
using namespace test_utilities;
template<typename PolyCollection,typename ValueFactory,typename... Types>
void test_comparison()
{
{
PolyCollection p1,p2;
const PolyCollection& cp1=p1;
const PolyCollection& cp2=p2;
BOOST_TEST(cp1==cp1);
BOOST_TEST(!(cp1!=cp1));
BOOST_TEST(cp1==cp2);
BOOST_TEST(!(cp1!=cp2));
}
{
PolyCollection p1,p2;
const PolyCollection& cp1=p1;
const PolyCollection& cp2=p2;
ValueFactory v;
fill<
constraints<is_not_equality_comparable>,
Types...
>(p1,v,2);
BOOST_TEST(!(cp1==cp2));
BOOST_TEST(cp1!=cp2);
}
{
PolyCollection p1,p2;
const PolyCollection& cp1=p1;
const PolyCollection& cp2=p2;
ValueFactory v;
p1.template register_types<Types...>();
fill<
constraints<is_not_equality_comparable>,
Types...
>(p1,v,2);
BOOST_TEST(!(cp1==cp2));
BOOST_TEST(cp1!=cp2);
}
{
PolyCollection p1,p2;
const PolyCollection& cp1=p1;
const PolyCollection& cp2=p2;
ValueFactory v;
fill<
constraints<is_not_equality_comparable>,
Types...
>(p1,v,1);
fill<
constraints<is_not_equality_comparable>,
Types...
>(p2,v,2);
BOOST_TEST(!(cp1==cp2));
BOOST_TEST(cp1!=cp2);
}
{
using not_equality_comparable=
boost::poly_collection::not_equality_comparable;
PolyCollection p1,p2;
const PolyCollection& cp1=p1;
const PolyCollection& cp2=p2;
ValueFactory v;
fill<
constraints<is_not_equality_comparable>,
Types...
>(p1,v,2);
fill<
constraints<is_not_equality_comparable>,
Types...
>(p2,v,2);
check_throw<not_equality_comparable>(
[&]{(void)(cp1==cp2);},
[&]{(void)(cp1!=cp2);});
}
{
PolyCollection p1,p2;
const PolyCollection& cp1=p1;
const PolyCollection& cp2=p2;
ValueFactory v;
fill<
constraints<is_not_equality_comparable>,
Types...
>(p1,v,2);
fill<
constraints<is_equality_comparable,is_copy_constructible>,
Types...
>(p2,v,2);
p1.insert(p2.begin(),p2.end());
BOOST_TEST(!(cp1==cp2));
BOOST_TEST(cp1!=cp2);
}
{
PolyCollection p1,p2;
const PolyCollection& cp1=p1;
const PolyCollection& cp2=p2;
ValueFactory v;
p1.template register_types<Types...>();
fill<
constraints<is_equality_comparable,is_copy_constructible>,
Types...
>(p2,v,2);
p1.insert(p2.begin(),p2.end());
BOOST_TEST(cp1==cp2);
BOOST_TEST(!(cp1!=cp2));
p1.erase(p1.begin());
BOOST_TEST(!(cp1==cp2));
BOOST_TEST(cp1!=cp2);
}
}
void test_comparison()
{
test_comparison<
any_types::collection,auto_increment,
any_types::t1,any_types::t2,any_types::t3,
any_types::t4,any_types::t5>();
test_comparison<
base_types::collection,auto_increment,
base_types::t1,base_types::t2,base_types::t3,
base_types::t4,base_types::t5>();
test_comparison<
function_types::collection,auto_increment,
function_types::t1,function_types::t2,function_types::t3,
function_types::t4,function_types::t5>();
}

View File

@@ -0,0 +1,9 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
void test_comparison();

View File

@@ -0,0 +1,16 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include <boost/core/lightweight_test.hpp>
#include "test_comparison.hpp"
int main()
{
test_comparison();
return boost::report_errors();
}

View File

@@ -0,0 +1,263 @@
/* Copyright 2016-2017 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include "test_construction.hpp"
#include <algorithm>
#include <boost/config.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/type_erasure/any_cast.hpp>
#include <boost/type_erasure/relaxed.hpp>
#include <scoped_allocator>
#include <utility>
#include <vector>
#include "any_types.hpp"
#include "base_types.hpp"
#include "function_types.hpp"
#include "test_utilities.hpp"
using namespace test_utilities;
template<typename PolyCollection,typename ValueFactory,typename... Types>
void test_construction()
{
{
PolyCollection p;
const PolyCollection& cp=p;
ValueFactory v;
fill<
constraints<is_equality_comparable,is_copy_constructible>,
Types...
>(p,v,2);
{
PolyCollection p2{cp};
BOOST_TEST(p2==p);
}
{
PolyCollection p2;
p2=cp;
BOOST_TEST(p2==p);
}
{
PolyCollection p2{cp};
auto d2=get_layout_data<Types...>(p2);
PolyCollection p3{std::move(p2)};
auto d3=get_layout_data<Types...>(p3);
BOOST_TEST(d2==d3);
BOOST_TEST(p2.empty());
do_((BOOST_TEST(!p2.template is_registered<Types>()),0)...);
}
{
PolyCollection p2{cp};
auto d2=get_layout_data<Types...>(p2);
PolyCollection p3;
p3={std::move(p2)};
auto d3=get_layout_data<Types...>(p3);
BOOST_TEST(d2==d3);
BOOST_TEST(p2.empty());
do_((BOOST_TEST(!p2.template is_registered<Types>()),0)...);
}
{
PolyCollection p2{cp.begin(),cp.end()};
BOOST_TEST(p2==p);
}
{
using type=first_of<
constraints<is_equality_comparable,is_copy_constructible>,
Types...>;
PolyCollection p2{cp.template begin<type>(),cp.template end<type>()};
BOOST_TEST(
p2.size()==cp.template size<type>()&&
std::equal(
p2.template begin<type>(),p2.template end<type>(),
cp.template begin<type>()));
}
}
{
using rooted_poly_collection=
realloc_poly_collection<PolyCollection,rooted_allocator>;
using allocator_type=typename rooted_poly_collection::allocator_type;
allocator_type root1{0},root2{0};
rooted_poly_collection p{root1};
const rooted_poly_collection& cp=p;
ValueFactory v;
fill<
constraints<is_equality_comparable,is_copy_constructible>,
Types...
>(p,v,2);
{
rooted_poly_collection p2{cp,root2};
BOOST_TEST(p2==p);
BOOST_TEST(p2.get_allocator()==root2);
}
{
rooted_poly_collection p2{root2};
p2=cp;
BOOST_TEST(p2==p);
BOOST_TEST(p2.get_allocator().root==&root2);
}
#if BOOST_WORKAROUND(BOOST_LIBSTDCXX_VERSION,<40900)
/* Limitations from libstdc++-v3 make move construction with allocator
* decay to copy construction with allocator.
*/
#else
{
rooted_poly_collection p2{cp};
auto d2=get_layout_data<Types...>(p2);
rooted_poly_collection p3{std::move(p2),root2};
auto d3=get_layout_data<Types...>(p3);
BOOST_TEST(d2==d3);
BOOST_TEST(p2.empty());
do_((BOOST_TEST(!p2.template is_registered<Types>()),0)...);
BOOST_TEST(p3.get_allocator().root==&root2);
}
#endif
{
rooted_poly_collection p2{cp};
auto d2=get_layout_data<Types...>(p2);
rooted_poly_collection p3{root2};
p3=std::move(p2);
auto d3=get_layout_data<Types...>(p3);
BOOST_TEST(d2==d3);
BOOST_TEST(p2.empty());
do_((BOOST_TEST(!p2.template is_registered<Types>()),0)...);
#if BOOST_WORKAROUND(BOOST_MSVC,<=1900)||\
BOOST_WORKAROUND(BOOST_LIBSTDCXX_VERSION,<40900)
#else
BOOST_TEST(p3.get_allocator().root==&root1);
#endif
}
}
{
using not_copy_constructible=
boost::poly_collection::not_copy_constructible;
PolyCollection p;
const PolyCollection& cp=p;
ValueFactory v;
fill<
constraints<is_equality_comparable,is_not_copy_constructible>,
Types...
>(p,v,2);
#if BOOST_WORKAROUND(BOOST_LIBSTDCXX_VERSION,<40900)
/* std::unordered_map copy construction and assigment crash when elements
* throw on copy construction.
*/
static_assert(
sizeof(not_copy_constructible)>0,""); /* Wunused-local-typedefs */
(void)cp; /* Wunused-variable */
#else
check_throw<not_copy_constructible>([&]{
PolyCollection p2{cp};
(void)p2;
});
check_throw<not_copy_constructible>([&]{
PolyCollection p2;
p2=cp;
});
#endif
{
PolyCollection p2{std::move(p)};
BOOST_TEST(!p2.empty());
BOOST_TEST(p.empty());
do_((BOOST_TEST(!p.template is_registered<Types>()),0)...);
p={std::move(p2)};
BOOST_TEST(!p.empty());
BOOST_TEST(p2.empty());
do_((BOOST_TEST(!p2.template is_registered<Types>()),0)...);
}
}
{
PolyCollection p1,p2;
ValueFactory v;
fill<constraints<>,Types...>(p1,v,2);
auto d1=get_layout_data<Types...>(p1),
d2=get_layout_data<Types...>(p2);
p1.swap(p2);
auto e1=get_layout_data<Types...>(p1),
e2=get_layout_data<Types...>(p2);
BOOST_TEST(d1==e2);
BOOST_TEST(d2==e1);
do_((BOOST_TEST(!p1.template is_registered<Types>()),0)...);
using std::swap;
swap(p1,p2);
auto f1=get_layout_data<Types...>(p1),
f2=get_layout_data<Types...>(p2);
BOOST_TEST(e1==f2);
BOOST_TEST(e2==f1);
do_((BOOST_TEST(!p2.template is_registered<Types>()),0)...);
}
}
void test_scoped_allocator()
{
using vector_allocator=rooted_allocator<char>;
using vector=std::vector<char,vector_allocator>;
using concept_=boost::type_erasure::relaxed;
using element_allocator=rooted_allocator<
boost::poly_collection::any_collection_value_type<concept_>
>;
using collection_allocator=std::scoped_allocator_adaptor<
element_allocator,
vector_allocator
>;
using poly_collection=
boost::any_collection<concept_,collection_allocator>;
element_allocator roote{0};
vector_allocator rootv{0};
collection_allocator al{roote,rootv};
poly_collection p{al};
p.emplace<vector>();
auto& s=boost::type_erasure::any_cast<vector&>(*p.begin());
BOOST_TEST(p.get_allocator().root==&roote);
#if BOOST_WORKAROUND(BOOST_MSVC,>=1910)
/* https://connect.microsoft.com/VisualStudio/feedback/details/3136309 */
#else
BOOST_TEST(s.get_allocator().root==&rootv);
#endif
}
void test_construction()
{
test_construction<
any_types::collection,auto_increment,
any_types::t1,any_types::t2,any_types::t3,
any_types::t4,any_types::t5>();
test_construction<
base_types::collection,auto_increment,
base_types::t1,base_types::t2,base_types::t3,
base_types::t4,base_types::t5>();
test_construction<
function_types::collection,auto_increment,
function_types::t1,function_types::t2,function_types::t3,
function_types::t4,function_types::t5>();
test_scoped_allocator();
}

View File

@@ -0,0 +1,9 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
void test_construction();

View File

@@ -0,0 +1,16 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include <boost/core/lightweight_test.hpp>
#include "test_construction.hpp"
int main()
{
test_construction();
return boost::report_errors();
}

View File

@@ -0,0 +1,121 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include "test_emplacement.hpp"
#include <boost/core/lightweight_test.hpp>
#include "any_types.hpp"
#include "base_types.hpp"
#include "function_types.hpp"
#include "test_utilities.hpp"
using namespace test_utilities;
template<typename PolyCollection,typename ValueFactory,typename... Types>
void test_emplacement()
{
{
using type=first_of<
constraints<
is_constructible_from_int,is_not_copy_constructible,
is_not_copy_assignable,
is_equality_comparable
>,
Types...
>;
using iterator=typename PolyCollection::iterator;
using local_base_iterator=typename PolyCollection::local_base_iterator;
using local_iterator=
typename PolyCollection::template local_iterator<type>;
PolyCollection p;
iterator it=p.template emplace<type>(4);
BOOST_TEST(*p.template begin<type>()==type{4});
BOOST_TEST(&*it==&*p.begin(typeid(type)));
iterator it2=p.template emplace_hint<type>(it,3);
BOOST_TEST(*p.template begin<type>()==type{3});
BOOST_TEST(&*it2==&*p.begin(typeid(type)));
iterator it3=p.template emplace_hint<type>(p.cend(),5);
BOOST_TEST(*(p.template end<type>()-1)==type{5});
BOOST_TEST(&*it3==&*(p.end(typeid(type))-1));
local_base_iterator lbit=
p.template emplace_pos<type>(p.begin(typeid(type)),2);
BOOST_TEST(*static_cast<local_iterator>(lbit)==type{2});
BOOST_TEST(lbit==p.begin(typeid(type)));
local_base_iterator lbit2=
p.template emplace_pos<type>(p.cend(typeid(type)),6);
BOOST_TEST(*static_cast<local_iterator>(lbit2)==type{6});
BOOST_TEST(lbit2==p.end(typeid(type))-1);
local_iterator lit=p.emplace_pos(p.template begin<type>(),1);
BOOST_TEST(*lit==type{1});
BOOST_TEST(lit==p.template begin<type>());
local_iterator lit2=p.emplace_pos(p.template cend<type>(),7);
BOOST_TEST(*lit2==type{7});
BOOST_TEST(lit2==p.template end<type>()-1);
}
{
using type=first_of<
constraints<is_default_constructible>,
Types...
>;
PolyCollection p;
p.template emplace<type>();
p.template emplace_hint<type>(p.begin());
p.template emplace_hint<type>(p.cend());
p.template emplace_pos<type>(p.begin(typeid(type)));
p.template emplace_pos<type>(p.cend(typeid(type)));
p.emplace_pos(p.template begin<type>());
p.emplace_pos(p.template cend<type>());
BOOST_TEST(p.size()==7);
}
{
using type=first_of<
constraints<is_not_copy_constructible>,
Types...
>;
PolyCollection p;
ValueFactory v;
p.template emplace<type>(v.template make<type>());
p.template emplace_hint<type>(p.begin(),v.template make<type>());
p.template emplace_hint<type>(p.cend(),v.template make<type>());
p.template emplace_pos<type>(
p.begin(typeid(type)),v.template make<type>());
p.template emplace_pos<type>(
p.cend(typeid(type)),v.template make<type>());
p.emplace_pos(p.template begin<type>(),v.template make<type>());
p.emplace_pos(p.template cend<type>(),v.template make<type>());
BOOST_TEST(p.size()==7);
}
}
void test_emplacement()
{
test_emplacement<
any_types::collection,auto_increment,
any_types::t1,any_types::t2,any_types::t3,
any_types::t4,any_types::t5>();
test_emplacement<
base_types::collection,auto_increment,
base_types::t1,base_types::t2,base_types::t3,
base_types::t4,base_types::t5>();
test_emplacement<
function_types::collection,auto_increment,
function_types::t1,function_types::t2,function_types::t3,
function_types::t4,function_types::t5>();
}

View File

@@ -0,0 +1,9 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
void test_emplacement();

View File

@@ -0,0 +1,16 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include <boost/core/lightweight_test.hpp>
#include "test_emplacement.hpp"
int main()
{
test_emplacement();
return boost::report_errors();
}

View File

@@ -0,0 +1,151 @@
/* Copyright 2016-2017 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include "test_erasure.hpp"
#include <boost/core/lightweight_test.hpp>
#include <iterator>
#include "any_types.hpp"
#include "base_types.hpp"
#include "function_types.hpp"
#include "test_utilities.hpp"
using namespace test_utilities;
template<typename Type,typename PolyCollection>
void test_local_erase(const PolyCollection& p2)
{
using size_type=typename PolyCollection::size_type;
for(size_type i=0;i<p2.template size<Type>();++i){
PolyCollection p=p2;
auto it=p.erase(p.template cbegin<Type>()+i);
BOOST_TEST(it-p.template begin<Type>()==(std::ptrdiff_t)i);
BOOST_TEST(p.template size<Type>()==p2.template size<Type>()-1);
}
}
template<typename Type,typename PolyCollection>
void test_local_range_erase(const PolyCollection& p2)
{
using size_type=typename PolyCollection::size_type;
for(size_type i=0;i<=p2.template size<Type>();++i){
for(size_type j=i;j<=p2.template size<Type>();++j){
PolyCollection p=p2;
auto first=p.template cbegin<Type>()+i,
last=p.template cbegin<Type>()+j;
auto it=p.erase(first,last);
BOOST_TEST(it-p.template begin<Type>()==(std::ptrdiff_t)i);
BOOST_TEST(p.template size<Type>()==p2.template size<Type>()-(j-i));
}
}
}
template<typename Type,typename PolyCollection>
void test_local_clear(const PolyCollection& p2)
{
PolyCollection p=p2;
p.template clear<Type>();
BOOST_TEST(p.template empty<Type>());
BOOST_TEST(p.size()==p2.size()-p2.template size<Type>());
}
template<typename PolyCollection,typename ValueFactory,typename... Types>
void test_erasure()
{
using size_type=typename PolyCollection::size_type;
PolyCollection p,p2;
ValueFactory v;
fill<constraints<is_copy_constructible>,Types...>(p2,v,5);
auto sit=p2.segment_traversal().begin();
p2.clear(sit->type_info());
++sit;++sit;
p2.clear(sit->type_info());
for(size_type i=0;i<p2.size();++i){
p=p2;
auto it=p.erase(std::next(p.cbegin(),i));
BOOST_TEST(std::distance(p.begin(),it)==(std::ptrdiff_t)i);
BOOST_TEST(p.size()==p2.size()-1);
}
for(auto s:p2.segment_traversal()){
auto& info=s.type_info();
for(size_type i=0;i<p2.size(info);++i){
p=p2;
auto it=p.erase(p.cbegin(info)+i);
BOOST_TEST(it-p.begin(info)==(std::ptrdiff_t)i);
BOOST_TEST(p.size(info)==p2.size(info)-1);
}
}
do_((
p2.template is_registered<Types>()?test_local_erase<Types>(p2),0:0)...);
for(size_type i=0;i<=p2.size();++i){
for(size_type j=i;j<=p2.size();++j){
p=p2;
auto first=std::next(p.cbegin(),i),
last=std::next(p.cbegin(),j);
auto it=p.erase(first,last);
BOOST_TEST(std::distance(p.begin(),it)==(std::ptrdiff_t)i);
BOOST_TEST(p.size()==p2.size()-(j-i));
}
}
for(auto s:p2.segment_traversal()){
auto& info=s.type_info();
for(size_type i=0;i<=p2.size(info);++i){
for(size_type j=i;j<=p2.size(info);++j){
p=p2;
auto first=p.cbegin(info)+i,
last=p.cbegin(info)+j;
auto it=p.erase(first,last);
BOOST_TEST(it-p.begin(info)==(std::ptrdiff_t)i);
BOOST_TEST(p.size(info)==p2.size(info)-(j-i));
}
}
}
do_((p2.template is_registered<Types>()?
test_local_range_erase<Types>(p2),0:0)...);
p=p2;
p.clear();
BOOST_TEST(p.empty());
for(auto s:p2.segment_traversal()){
auto& info=s.type_info();
p=p2;
p.clear(info);
BOOST_TEST(p.empty(info));
BOOST_TEST(p.size()==p2.size()-p2.size(info));
}
do_((p2.template is_registered<Types>()?
test_local_clear<Types>(p2),0:0)...);
}
void test_erasure()
{
test_erasure<
any_types::collection,auto_increment,
any_types::t1,any_types::t2,any_types::t3,
any_types::t4,any_types::t5>();
test_erasure<
base_types::collection,auto_increment,
base_types::t1,base_types::t2,base_types::t3,
base_types::t4,base_types::t5>();
test_erasure<
function_types::collection,auto_increment,
function_types::t1,function_types::t2,function_types::t3,
function_types::t4,function_types::t5>();
}

View File

@@ -0,0 +1,9 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
void test_erasure();

View File

@@ -0,0 +1,16 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include <boost/core/lightweight_test.hpp>
#include "test_erasure.hpp"
int main()
{
test_erasure();
return boost::report_errors();
}

View File

@@ -0,0 +1,354 @@
/* Copyright 2016-2017 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include "test_insertion.hpp"
#include <algorithm>
#include <boost/core/lightweight_test.hpp>
#include <numeric>
#include <vector>
#include "any_types.hpp"
#include "base_types.hpp"
#include "function_types.hpp"
#include "test_utilities.hpp"
using namespace test_utilities;
template<typename PolyCollection,typename ValueFactory,typename... Types>
void test_insertion()
{
{
using unregistered_type=boost::poly_collection::unregistered_type;
using type=first_of<constraints<is_copy_constructible>,Types...>;
PolyCollection p,p2;
ValueFactory v;
p2.insert(v.template make<type>());
check_throw<unregistered_type>(
[&]{p.insert(*p2.begin());},
[&]{p.insert(p.end(),*p2.begin());},
[&]{p.insert(p.cend(),*p2.begin());},
[&]{p.insert(
external_iterator(p2.begin()),external_iterator(p2.end()));},
[&]{p.insert(
p.end(),
external_iterator(p2.begin()),external_iterator(p2.end()));},
[&]{p.insert(
p.cend(),
external_iterator(p2.begin()),external_iterator(p2.end()));});
}
{
using not_copy_constructible=
boost::poly_collection::not_copy_constructible;
using type=first_of<constraints<is_not_copy_constructible>,Types...>;
PolyCollection p,p2;
ValueFactory v;
p.template register_types<type>();
p2.insert(v.template make<type>());
auto p2b=external_iterator(p2.begin()),
p2e=external_iterator(p2.end());
auto p2lb=external_iterator(p2.template begin<type>()),
p2le=external_iterator(p2.template end<type>());
check_throw<not_copy_constructible>(
[&]{p.insert(*p2.begin());},
[&]{p.insert(p.end(),*p2.begin());},
[&]{p.insert(p.cend(),*p2.cbegin());},
[&]{p.insert(p.end(typeid(type)),*p2.begin());},
[&]{p.insert(p.cend(typeid(type)),*p2.begin());},
[&]{p.insert(p.template end<type>(),*p2.begin());},
[&]{p.insert(p.template cend<type>(),*p2.begin());},
[&]{p.insert(p2b,p2e);},
[&]{p.insert(p2lb,p2le);},
[&]{p.insert(p2.begin(),p2.end());},
[&]{p.insert(p2.begin(typeid(type)),p2.end(typeid(type)));},
[&]{p.insert(p2.template begin<type>(),p2.template end<type>());},
[&]{p.insert(p.end(),p2b,p2e);},
[&]{p.insert(p.end(),p2lb,p2le);},
[&]{p.insert(p.end(),p2.begin(),p2.end());},
[&]{p.insert(p.end(),p2.begin(typeid(type)),p2.end(typeid(type)));},
[&]{p.insert(
p.end(),p2.template begin<type>(),p2.template end<type>());},
[&]{p.insert(p.cend(),p2b,p2e);},
[&]{p.insert(p.cend(),p2lb,p2le);},
[&]{p.insert(p.cend(),p2.begin(),p2.end());},
[&]{p.insert(p.cend(),p2.begin(typeid(type)),p2.end(typeid(type)));},
[&]{p.insert(
p.cend(),p2.template begin<type>(),p2.template end<type>());},
[&]{p.insert(p.end(typeid(type)),p2b,p2e);},
[&]{p.insert(p.cend(typeid(type)),p2b,p2e);},
[&]{p.insert(p.template end<type>(),p2b,p2e);},
[&]{p.insert(p.template cend<type>(),p2b,p2e);});
}
{
PolyCollection p;
ValueFactory v;
fill<constraints<>,Types...>(p,v,2);
do_((BOOST_TEST(
is_last(
p,typeid(Types),
p.insert(constref_if_copy_constructible(v.template make<Types>())))
),0)...);
}
{
PolyCollection p;
ValueFactory v;
fill<constraints<>,Types...>(p,v,2);
auto& info=p.segment_traversal().begin()->type_info();
do_((BOOST_TEST(
info==typeid(Types)?
is_first(
p,typeid(Types),
p.insert(
p.cbegin(),
constref_if_copy_constructible(v.template make<Types>()))):
is_last(
p,typeid(Types),
p.insert(
p.cbegin(),
constref_if_copy_constructible(v.template make<Types>())))
),0)...);
do_((BOOST_TEST(
is_first(
p,typeid(Types),
p.insert(
p.cbegin(typeid(Types)),
constref_if_copy_constructible(v.template make<Types>())))
),0)...);
do_((BOOST_TEST(
is_first<Types>(
p,
p.insert(
p.template cbegin<Types>(),
constref_if_copy_constructible(v.template make<Types>())))
),0)...);
}
{
PolyCollection p,p2;
ValueFactory v;
p.template register_types<Types...>();
p2.template register_types<Types...>();
fill<
constraints<is_copy_constructible,is_equality_comparable>,
Types...
>(p2,v,2);
p.insert(external_iterator(p2.begin()),external_iterator(p2.end()));
BOOST_TEST(p==p2);
p.clear();
p.insert(p2.begin(),p2.end());
BOOST_TEST(p==p2);
p.clear();
p.insert(p2.cbegin(),p2.cend());
BOOST_TEST(p==p2);
p.clear();
for(auto s:p2.segment_traversal()){
p.insert(s.begin(),s.end());
BOOST_TEST(p.size()==p2.size(s.type_info()));
p.clear();
p.insert(s.cbegin(),s.cend());
BOOST_TEST(p.size()==p2.size(s.type_info()));
p.clear();
}
do_((
p.insert(
external_iterator(p2.template begin<Types>()),
external_iterator(p2.template end<Types>())),
BOOST_TEST(p.size()==p2.template size<Types>()),
p.clear()
,0)...);
do_((
p.insert(p2.template begin<Types>(),p2.template end<Types>()),
BOOST_TEST(p.size()==p2.template size<Types>()),
p.clear()
,0)...);
do_((
p.insert(p2.template cbegin<Types>(),p2.template cend<Types>()),
BOOST_TEST(p.size()==p2.template size<Types>()),
p.clear()
,0)...);
}
{
PolyCollection p,p1,p2;
ValueFactory v;
p2.template register_types<Types...>();
fill<
constraints<is_copy_constructible,is_equality_comparable>,
Types...
>(p1,v,2);
fill<
constraints<is_copy_constructible,is_equality_comparable>,
Types...
>(p2,v,2);
auto remove_original=[](PolyCollection& p)
{
bool first=true;
for(auto s:p.segment_traversal()){
if(first)p.erase(s.end()-2,s.end()),first=false;
else p.erase(s.begin(),s.begin()+2);
}
};
p=p1;
p.insert(
p.begin(),external_iterator(p2.begin()),external_iterator(p2.end()));
remove_original(p);
BOOST_TEST(p==p2);
p=p1;
p.insert(p.begin(),p2.begin(),p2.end());
remove_original(p);
BOOST_TEST(p==p2);
p=p1;
p.insert(p.begin(),p2.cbegin(),p2.cend());
remove_original(p);
BOOST_TEST(p==p2);
p=p1;
for(auto s:p2.segment_traversal())p.insert(p.begin(),s.begin(),s.end());
remove_original(p);
BOOST_TEST(p==p2);
p=p1;
for(auto s:p2.segment_traversal())p.insert(p.begin(),s.cbegin(),s.cend());
remove_original(p);
BOOST_TEST(p==p2);
p=p1;
do_((p.insert(
p.begin(),
external_iterator(p2.template begin<Types>()),
external_iterator(p2.template end<Types>())),0)...);
remove_original(p);
BOOST_TEST(p==p2);
p=p1;
do_((p.insert(
p.begin(),p2.template begin<Types>(),p2.template end<Types>()),0)...);
remove_original(p);
BOOST_TEST(p==p2);
p=p1;
do_((p.insert(
p.begin(),p2.template cbegin<Types>(),p2.template cend<Types>()),0)...);
remove_original(p);
BOOST_TEST(p==p2);
}
{
using type=first_of<
constraints<is_copy_constructible,is_equality_comparable>,
Types...
>;
PolyCollection p,p1,p2;
ValueFactory v;
fill<constraints<>,type>(p1,v,2);
fill<constraints<>,type>(p2,v,2);
auto remove_original=[](PolyCollection& p)
{
auto it=p.segment_traversal().begin()->end();
p.erase(it-2,it);
};
p=p1;
BOOST_TEST(is_first(
p,typeid(type),
p.insert(
p.begin(typeid(type)),
external_iterator(p2.begin()),external_iterator(p2.end()))));
remove_original(p);
BOOST_TEST(p==p2);
p=p1;
BOOST_TEST(is_first(
p,typeid(type),
p.insert(
p.cbegin(typeid(type)),
external_iterator(p2.begin()),external_iterator(p2.end()))));
remove_original(p);
BOOST_TEST(p==p2);
p=p1;
BOOST_TEST(is_first<type>(
p,
p.insert(
p.template begin<type>(),
external_iterator(p2.begin()),external_iterator(p2.end()))));
remove_original(p);
BOOST_TEST(p==p2);
p=p1;
BOOST_TEST(is_first<type>(
p,
p.insert(
p.template cbegin<type>(),
external_iterator(p2.begin()),external_iterator(p2.end()))));
remove_original(p);
BOOST_TEST(p==p2);
}
{
using type=first_of<
constraints<
is_constructible_from_int,is_not_copy_constructible,
is_equality_comparable
>,
Types...
>;
PolyCollection p;
std::vector<int> s(10);
ValueFactory v;
fill<constraints<>,type>(p,v,2);
std::iota(s.begin(),s.end(),0);
BOOST_TEST(is_first<type>(
p,
p.insert(p.template begin<type>(),s.begin(),s.end())));
BOOST_TEST(
std::equal(s.begin(),s.end(),p.template begin<type>(),
[](int x,const type& y){return type{x}==y;})
);
}
}
void test_insertion()
{
test_insertion<
any_types::collection,auto_increment,
any_types::t1,any_types::t2,any_types::t3,
any_types::t4,any_types::t5>();
test_insertion<
base_types::collection,auto_increment,
base_types::t1,base_types::t2,base_types::t3,
base_types::t4,base_types::t5>();
test_insertion<
function_types::collection,auto_increment,
function_types::t1,function_types::t2,function_types::t3,
function_types::t4,function_types::t5>();
}

View File

@@ -0,0 +1,9 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
void test_insertion();

View File

@@ -0,0 +1,16 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include <boost/core/lightweight_test.hpp>
#include "test_insertion.hpp"
int main()
{
test_insertion();
return boost::report_errors();
}

View File

@@ -0,0 +1,310 @@
/* Copyright 2016-2017 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include "test_iterators.hpp"
#include <boost/core/lightweight_test.hpp>
#include <iterator>
#include <type_traits>
#include "any_types.hpp"
#include "base_types.hpp"
#include "function_types.hpp"
#include "test_utilities.hpp"
using namespace test_utilities;
template<typename Iterator>
using is_input=std::is_base_of<
std::input_iterator_tag,
typename std::iterator_traits<Iterator>::iterator_category
>;
template<typename Iterator>
using is_forward=std::is_base_of<
std::forward_iterator_tag,
typename std::iterator_traits<Iterator>::iterator_category
>;
template<typename Iterator>
using is_random_access=std::is_base_of<
std::random_access_iterator_tag,
typename std::iterator_traits<Iterator>::iterator_category
>;
template<typename Type,typename PolyCollection>
void test_iterators(PolyCollection& p)
{
using local_base_iterator=typename PolyCollection::local_base_iterator;
using const_local_base_iterator=
typename PolyCollection::const_local_base_iterator;
using local_iterator=typename PolyCollection::template local_iterator<Type>;
using const_local_iterator=
typename PolyCollection::template const_local_iterator<Type>;
using base_segment_info=typename PolyCollection::base_segment_info;
using const_base_segment_info=
typename PolyCollection::const_base_segment_info;
using const_segment_info=
typename PolyCollection::template const_segment_info<Type>;
using segment_info=typename PolyCollection::template segment_info<Type>;
static_assert(is_random_access<local_iterator>::value,
"local_iterator must be random access");
static_assert(is_random_access<const_local_iterator>::value,
"const_local_iterator must be random access");
static_assert(std::is_base_of<const_segment_info,segment_info>::value,
"segment_info must derive from const_segment_info");
{
local_iterator lit;
const_local_iterator clit,clit2(lit); /* sorry about the names */
lit=lit;
clit=clit2;
clit=lit;
}
const PolyCollection& cp=p;
std::size_t n=0;
local_base_iterator lbfirst=p.begin(typeid(Type)),
lblast=p.end(typeid(Type));
const_local_base_iterator clbfirst=cp.begin(typeid(Type)),
clblast=cp.end(typeid(Type));
local_iterator lfirst=p.template begin<Type>(),
llast=p.template end<Type>();
const_local_iterator clfirst=cp.template begin<Type>(),
cllast=cp.template end<Type>();
base_segment_info bi=p.segment(typeid(Type));
const_base_segment_info cbi=cp.segment(typeid(Type));
segment_info i=p.template segment<Type>();
const_segment_info ci=cp.template segment<Type>();
BOOST_TEST(clbfirst==cp.cbegin(typeid(Type)));
BOOST_TEST(clblast==cp.cend(typeid(Type)));
BOOST_TEST(clfirst==cp.template cbegin<Type>());
BOOST_TEST(cllast==cp.template cend<Type>());
BOOST_TEST(lbfirst==bi.begin());
BOOST_TEST(lblast==bi.end());
BOOST_TEST(clbfirst==bi.cbegin());
BOOST_TEST(clbfirst==cbi.begin());
BOOST_TEST(clblast==bi.cend());
BOOST_TEST(clblast==cbi.end());
BOOST_TEST(lfirst==i.begin());
BOOST_TEST(llast==i.end());
BOOST_TEST(clfirst==i.cbegin());
BOOST_TEST(clfirst==ci.begin());
BOOST_TEST(cllast==i.cend());
BOOST_TEST(cllast==ci.end());
for(;lbfirst!=lblast;++lbfirst,++clbfirst,++lfirst,++clfirst){
BOOST_TEST(lfirst==static_cast<local_iterator>(lbfirst));
BOOST_TEST(static_cast<local_base_iterator>(lfirst)==lbfirst);
BOOST_TEST(clfirst==static_cast<const_local_iterator>(clbfirst));
BOOST_TEST(static_cast<const_local_base_iterator>(clfirst)==clbfirst);
BOOST_TEST(clfirst==lfirst);
BOOST_TEST(&*lfirst==&*static_cast<local_iterator>(lbfirst));
BOOST_TEST(&*clfirst==&*static_cast<const_local_iterator>(clbfirst));
BOOST_TEST(&*clfirst==&*lfirst);
Type& r=p.template begin<Type>()[n];
const Type& cr=cp.template begin<Type>()[n];
BOOST_TEST(&*lfirst==&r);
BOOST_TEST(&*clfirst==&cr);
++n;
}
BOOST_TEST(clbfirst==clblast);
BOOST_TEST(lfirst==llast);
BOOST_TEST(clfirst==cllast);
BOOST_TEST(lfirst==static_cast<local_iterator>(llast));
BOOST_TEST(clfirst==static_cast<const_local_iterator>(cllast));
BOOST_TEST(clfirst==llast);
BOOST_TEST((std::ptrdiff_t)n==p.end(typeid(Type))-p.begin(typeid(Type)));
BOOST_TEST(
(std::ptrdiff_t)n==p.template end<Type>()-p.template begin<Type>());
for(auto s:p.segment_traversal()){
if(s.type_info()==typeid(Type)){
const auto& cs=s;
BOOST_TEST(
s.template begin<Type>()==
static_cast<local_iterator>(s.begin()));
BOOST_TEST(
s.template end<Type>()==
static_cast<local_iterator>(s.end()));
BOOST_TEST(
cs.template begin<Type>()==
static_cast<const_local_iterator>(cs.begin()));
BOOST_TEST(
cs.template end<Type>()==
static_cast<const_local_iterator>(cs.end()));
BOOST_TEST(
cs.template cbegin<Type>()==
static_cast<const_local_iterator>(cs.cbegin()));
BOOST_TEST(
cs.template cend<Type>()==
static_cast<const_local_iterator>(cs.cend()));
}
}
}
template<typename PolyCollection,typename ValueFactory,typename... Types>
void test_iterators()
{
using value_type=typename PolyCollection::value_type;
using iterator=typename PolyCollection::iterator;
using const_iterator=typename PolyCollection::const_iterator;
using local_base_iterator=typename PolyCollection::local_base_iterator;
using const_local_base_iterator=
typename PolyCollection::const_local_base_iterator;
using const_base_segment_info=
typename PolyCollection::const_base_segment_info;
using base_segment_info=typename PolyCollection::base_segment_info;
using base_segment_info_iterator=
typename PolyCollection::base_segment_info_iterator;
using const_base_segment_info_iterator=
typename PolyCollection::const_base_segment_info_iterator;
using const_segment_traversal_info=
typename PolyCollection::const_segment_traversal_info;
using segment_traversal_info=
typename PolyCollection::segment_traversal_info;
static_assert(is_forward<iterator>::value,
"iterator must be forward");
static_assert(is_forward<const_iterator>::value,
"const_iterator must be forward");
static_assert(is_random_access<local_base_iterator>::value,
"local_base_iterator must be random access");
static_assert(is_random_access<const_local_base_iterator>::value,
"const_local_base_iterator must be random access");
static_assert(std::is_base_of<
const_base_segment_info,base_segment_info>::value,
"base_segment_info must derive from const_base_segment_info");
static_assert(is_input<base_segment_info_iterator>::value,
"base_segment_info_iterator must be input");
static_assert(is_input<const_base_segment_info_iterator>::value,
"const_base_segment_info_iterator must be input");
static_assert(std::is_base_of<
const_segment_traversal_info,segment_traversal_info>::value,
"const_segment_traversal_info must derive "\
"from segment_traversal_info");
{
iterator it;
const_iterator cit,cit2(it);
local_base_iterator lbit;
const_local_base_iterator clbit,clbit2(lbit);
base_segment_info_iterator sit;
const_base_segment_info_iterator csit,csit2(csit);
it=it;
cit=cit2;
cit=it;
lbit=lbit;
clbit=clbit2;
clbit=lbit;
sit=sit;
csit=csit2;
csit=sit;
}
PolyCollection p;
const PolyCollection& cp=p;
ValueFactory v;
fill<constraints<>,Types...>(p,v,2);
{
std::size_t n=0;
iterator first=p.begin(),last=p.end();
const_iterator cfirst=cp.begin(),clast=cp.end();
BOOST_TEST(cfirst==cp.cbegin());
BOOST_TEST(clast==cp.cend());
for(;first!=last;++first,++cfirst){
BOOST_TEST(first==cfirst);
BOOST_TEST(&*first==&*cfirst);
++n;
}
BOOST_TEST(cfirst==clast);
BOOST_TEST(last==clast);
BOOST_TEST(n==p.size());
}
{
std::size_t n=0;
base_segment_info_iterator first=p.segment_traversal().begin(),
last=p.segment_traversal().end();
const_base_segment_info_iterator cfirst=cp.segment_traversal().begin(),
clast=cp.segment_traversal().end();
BOOST_TEST(cfirst==cp.segment_traversal().cbegin());
BOOST_TEST(clast==cp.segment_traversal().cend());
for(;first!=last;++first,++cfirst){
BOOST_TEST(first==cfirst);
std::size_t m=0;
local_base_iterator lbfirst=first->begin(),lblast=first->end();
const_local_base_iterator clbfirst=cfirst->begin(),clblast=cfirst->end();
BOOST_TEST(clbfirst==cfirst->cbegin());
BOOST_TEST(clblast==cfirst->cend());
BOOST_TEST(lbfirst==p.begin(first->type_info()));
BOOST_TEST(lblast==p.end(first->type_info()));
BOOST_TEST(clbfirst==cp.begin(first->type_info()));
BOOST_TEST(clblast==cp.end(first->type_info()));
BOOST_TEST(clbfirst==cp.cbegin(first->type_info()));
BOOST_TEST(clblast==cp.cend(first->type_info()));
for(;lbfirst!=lblast;++lbfirst,++clbfirst){
BOOST_TEST(lbfirst==clbfirst);
BOOST_TEST(&*lbfirst==&*clbfirst);
value_type& r=first->begin()[m];
const value_type& cr=cfirst->begin()[m];
BOOST_TEST(&*lbfirst==&r);
BOOST_TEST(&*clbfirst==&cr);
++m;
}
BOOST_TEST(clbfirst==clblast);
BOOST_TEST(lblast==clblast);
BOOST_TEST((std::ptrdiff_t)m==first->end()-first->begin());
BOOST_TEST((std::ptrdiff_t)m==cfirst->end()-cfirst->begin());
BOOST_TEST((std::ptrdiff_t)m==cfirst->cend()-cfirst->cbegin());
n+=m;
}
BOOST_TEST(cfirst==clast);
BOOST_TEST(last==clast);
BOOST_TEST(n==p.size());
}
do_((test_iterators<Types>(p),0)...);
}
void test_iterators()
{
test_iterators<
any_types::collection,auto_increment,
any_types::t1,any_types::t2,any_types::t3,
any_types::t4,any_types::t5>();
test_iterators<
base_types::collection,auto_increment,
base_types::t1,base_types::t2,base_types::t3,
base_types::t4,base_types::t5>();
test_iterators<
function_types::collection,auto_increment,
function_types::t1,function_types::t2,function_types::t3,
function_types::t4,function_types::t5>();
}

View File

@@ -0,0 +1,9 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
void test_iterators();

View File

@@ -0,0 +1,16 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include <boost/core/lightweight_test.hpp>
#include "test_iterators.hpp"
int main()
{
test_iterators();
return boost::report_errors();
}

View File

@@ -0,0 +1,119 @@
/* Copyright 2016-2017 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include "test_registration.hpp"
#include <boost/core/lightweight_test.hpp>
#include <iterator>
#include "any_types.hpp"
#include "base_types.hpp"
#include "function_types.hpp"
#include "test_utilities.hpp"
using namespace test_utilities;
template<typename PolyCollection,typename Type>
void test_registration()
{
using unregistered_type=boost::poly_collection::unregistered_type;
{
PolyCollection p;
const PolyCollection& cp=p;
BOOST_TEST(!p.is_registered(typeid(Type)));
BOOST_TEST(!p.template is_registered<Type>());
check_throw<unregistered_type>(
[&]{(void)p.begin(typeid(Type));},
[&]{(void)p.end(typeid(Type));},
[&]{(void)cp.begin(typeid(Type));},
[&]{(void)cp.end(typeid(Type));},
[&]{(void)p.cbegin(typeid(Type));},
[&]{(void)p.cend(typeid(Type));},
[&]{(void)p.template begin<Type>();},
[&]{(void)p.template end<Type>();},
[&]{(void)cp.template begin<Type>();},
[&]{(void)cp.template end<Type>();},
[&]{(void)p.template cbegin<Type>();},
[&]{(void)p.template cend<Type>();},
[&]{(void)p.segment(typeid(Type));},
[&]{(void)cp.segment(typeid(Type));},
[&]{(void)p.template segment<Type>();},
[&]{(void)cp.template segment<Type>();},
[&]{(void)cp.empty(typeid(Type));},
[&]{(void)cp.size(typeid(Type));},
[&]{(void)cp.max_size(typeid(Type));},
[&]{(void)p.reserve(typeid(Type),0);},
[&]{(void)cp.capacity(typeid(Type));},
[&]{(void)p.shrink_to_fit(typeid(Type));},
[&]{(void)p.clear(typeid(Type));},
[&]{(void)cp.template empty<Type>();},
[&]{(void)cp.template size<Type>();},
[&]{(void)cp.template max_size<Type>();},
/* reserve<Type> omitted as it actually registers the type */
[&]{(void)cp.template capacity<Type>();},
[&]{(void)p.template shrink_to_fit<Type>();},
[&]{(void)p.template clear<Type>();});
p.register_types();
p.template register_types<>();
BOOST_TEST(!p.is_registered(typeid(Type)));
p.template register_types<Type>();
BOOST_TEST(p.is_registered(typeid(Type)));
BOOST_TEST(p.template is_registered<Type>());
(void)p.end(typeid(Type));
(void)cp.begin(typeid(Type));
(void)cp.end(typeid(Type));
(void)p.cbegin(typeid(Type));
(void)p.cend(typeid(Type));
(void)p.template begin<Type>();
(void)p.template end<Type>();
(void)cp.template begin<Type>();
(void)cp.template end<Type>();
(void)cp.template cbegin<Type>();
(void)cp.template cend<Type>();
(void)cp.empty(typeid(Type));
(void)cp.size(typeid(Type));
(void)cp.max_size(typeid(Type));
(void)p.reserve(typeid(Type),0);
(void)cp.capacity(typeid(Type));
(void)p.shrink_to_fit(typeid(Type));
(void)p.clear(typeid(Type));
(void)cp.template empty<Type>();
(void)cp.template size<Type>();
(void)cp.template max_size<Type>();
/* reserve<Type> omitted */
(void)cp.template capacity<Type>();
(void)p.template shrink_to_fit<Type>();
(void)p.template clear<Type>();
}
{
PolyCollection p;
p.template reserve<Type>(0);
BOOST_TEST(p.is_registered(typeid(Type)));
}
{
PolyCollection p;
p.template register_types<Type,Type,Type>();
BOOST_TEST(p.is_registered(typeid(Type)));
BOOST_TEST(
std::distance(
p.segment_traversal().begin(),p.segment_traversal().end())==1);
}
}
void test_registration()
{
test_registration<any_types::collection,any_types::t1>();
test_registration<base_types::collection,base_types::t1>();
test_registration<function_types::collection,function_types::t1>();
}

View File

@@ -0,0 +1,9 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
void test_registration();

View File

@@ -0,0 +1,16 @@
/* Copyright 2016 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#include <boost/core/lightweight_test.hpp>
#include "test_registration.hpp"
int main()
{
test_registration();
return boost::report_errors();
}

View File

@@ -0,0 +1,385 @@
/* Copyright 2016-2017 Joaquin M Lopez Munoz.
* 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)
*
* See http://www.boost.org/libs/poly_collection for library home page.
*/
#ifndef BOOST_POLY_COLLECTION_TEST_TEST_UTILITIES_HPP
#define BOOST_POLY_COLLECTION_TEST_TEST_UTILITIES_HPP
#if defined(_MSC_VER)
#pragma once
#endif
#include <array>
#include <boost/core/lightweight_test.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
#include <boost/type_traits/has_equal_to.hpp>
#include <iterator>
#include <memory>
#include <type_traits>
#include <typeinfo>
#include <utility>
namespace test_utilities{
template<typename... Values>
void do_(Values...){}
template<typename Exception,typename F>
void check_throw_case(F f)
{
try{
(void)f();
BOOST_TEST(false);
}
catch(const Exception&){}
catch(...){BOOST_TEST(false);}
}
template<typename Exception,typename... Fs>
void check_throw(Fs... f)
{
do_((check_throw_case<Exception>(f),0)...);
}
template<typename F1,typename F2>
struct compose_class
{
F1 f1;
F2 f2;
compose_class(const F1& f1,const F2& f2):f1(f1),f2(f2){}
template<typename T,typename... Args>
auto operator()(T&& x,Args&&... args)
->decltype(std::declval<F2>()(std::declval<F1>()(
std::forward<T>(x)),std::forward<Args>(args)...))
{
return f2(f1(std::forward<T>(x)),std::forward<Args>(args)...);
}
};
template<typename F1,typename F2>
compose_class<F1,F2> compose(F1 f1,F2 f2)
{
return {f1,f2};
}
template<typename F1,typename F2>
struct compose_all_class
{
F1 f1;
F2 f2;
compose_all_class(const F1& f1,const F2& f2):f1(f1),f2(f2){}
template<typename... Args>
auto operator()(Args&&... args)
->decltype(std::declval<F2>()(std::declval<F1>()(
std::forward<Args>(args))...))
{
return f2(f1(std::forward<Args>(args))...);
}
};
template<typename F1,typename F2>
compose_all_class<F1,F2> compose_all(F1 f1,F2 f2)
{
return {f1,f2};
}
using std::is_default_constructible;
using std::is_copy_constructible;
template<typename T>
using is_not_copy_constructible=std::integral_constant<
bool,
!std::is_copy_constructible<T>::value
>;
template<typename T>
using is_constructible_from_int=std::is_constructible<T,int>;
using std::is_copy_assignable;
template<typename T>
using is_not_copy_assignable=std::integral_constant<
bool,
!std::is_copy_assignable<T>::value
>;
template<typename T>
using is_equality_comparable=std::integral_constant<
bool,
boost::has_equal_to<T,T>::value
>;
template<typename T>
using is_not_equality_comparable=std::integral_constant<
bool,
!is_equality_comparable<T>::value
>;
template<
typename T,
typename std::enable_if<is_not_copy_constructible<T>::value>::type* =nullptr
>
typename std::remove_reference<T>::type&& constref_if_copy_constructible(T&& x)
{
return std::move(x);
}
template<
typename T,
typename std::enable_if<is_copy_constructible<T>::value>::type* =nullptr
>
const T& constref_if_copy_constructible(T&& x)
{
return x;
}
template<template<typename> class... Traits>
struct constraints;
template<>
struct constraints<>
{
template<typename T>
struct apply:std::true_type{};
};
template<
template <typename> class Trait,
template <typename> class... Traits
>
struct constraints<Trait,Traits...>
{
template<typename T>
struct apply:std::integral_constant<
bool,
Trait<T>::value&&constraints<Traits...>::template apply<T>::value
>{};
};
template<typename... Ts>struct type_list{};
template<
typename Constraints,template <typename...> class Template,
typename TypeList,
typename... Ts
>
struct instantiate_with_class;
template<
typename Constraints,template <typename...> class Template,
typename... Us
>
struct instantiate_with_class<Constraints,Template,type_list<Us...>>
{using type=Template<Us...>;};
template<
typename Constraints,template <typename...> class Template,
typename... Us,
typename T,typename... Ts
>
struct instantiate_with_class<
Constraints,Template,type_list<Us...>,T,Ts...
>:instantiate_with_class<
Constraints,Template,
typename std::conditional<
Constraints::template apply<T>::value,
type_list<Us...,T>,
type_list<Us...>
>::type,
Ts...
>{};
template<
typename Constraints,template <typename...> class Template,
typename... Ts
>
using instantiate_with=typename instantiate_with_class<
Constraints,Template,type_list<>,Ts...
>::type;
template<
template <typename...> class Template,typename... Ts
>
using only_eq_comparable=instantiate_with<
constraints<is_equality_comparable>,
Template, Ts...
>;
template<typename T> struct identity{using type=T;};
template<typename Constraints,typename... Ts>
struct first_of_class{};
template<typename Constraints,typename T,typename... Ts>
struct first_of_class<Constraints,T,Ts...>:std::conditional<
Constraints::template apply<T>::value,
identity<T>,
first_of_class<Constraints,Ts...>
>::type{};
template<typename Constraints,typename... Ts>
using first_of=typename first_of_class<Constraints,Ts...>::type;
template<
typename Constraints,typename... Ts,
typename PolyCollection,typename ValueFactory
>
void fill(PolyCollection& p,ValueFactory& v,int n)
{
for(int i=0;i<n;++i){
do_(
(Constraints::template apply<Ts>::value?
(p.insert(v.template make<Ts>()),0):0)...);
}
}
template<typename PolyCollection>
bool is_first(
const PolyCollection& p,typename PolyCollection::const_iterator it)
{
return it==p.begin();
}
template<typename PolyCollection,typename Iterator>
bool is_first(const PolyCollection& p,const std::type_info& info,Iterator it)
{
return &*it==&*p.begin(info);
}
template<typename PolyCollection,typename Iterator>
bool is_last(const PolyCollection& p,const std::type_info& info,Iterator it)
{
return &*it==&*(p.end(info)-1);
}
template<typename T,typename PolyCollection,typename Iterator>
bool is_first(const PolyCollection& p,Iterator it)
{
return &*it==&*p.template begin<T>();
}
template<typename T,typename PolyCollection,typename Iterator>
bool is_last(const PolyCollection& p,Iterator it)
{
return &*it==&*(p.template end<T>()-1);
}
template<typename Iterator>
struct external_iterator_class:
public boost::iterator_adaptor<external_iterator_class<Iterator>,Iterator>
{
external_iterator_class(const Iterator& it):
external_iterator_class::iterator_adaptor_{it}{}
};
template<typename Iterator>
external_iterator_class<Iterator> external_iterator(Iterator it)
{
return it;
}
template<typename Iterator>
struct unwrap_iterator_class:public boost::iterator_adaptor<
unwrap_iterator_class<Iterator>,
Iterator,
typename std::iterator_traits<Iterator>::value_type::type
>
{
unwrap_iterator_class(const Iterator& it):
unwrap_iterator_class::iterator_adaptor_{it}{}
};
template<typename Iterator>
unwrap_iterator_class<Iterator> unwrap_iterator(Iterator it)
{
return it;
}
struct auto_increment
{
template<typename T>
T make(){return T(n++);}
int n=0;
};
struct jammed_auto_increment
{
template<typename T>
T make(){return T(n++/10);}
int n=0;
};
template<typename T>
struct rooted_allocator:std::allocator<T>
{
using propagate_on_container_copy_assignment=std::false_type;
using propagate_on_container_move_assignment=std::true_type;
using propagate_on_container_swap=std::false_type;
template<typename U>
struct rebind{using other=rooted_allocator<U>;};
rooted_allocator()=default;
explicit rooted_allocator(int):root{this}{}
template<typename U>
rooted_allocator(const rooted_allocator<U>& x):root{x.root}{}
const void* root;
};
template<typename PolyCollection,template<typename> class Allocator>
struct realloc_poly_collection_class;
template<typename PolyCollection,template<typename> class Allocator>
using realloc_poly_collection=
typename realloc_poly_collection_class<PolyCollection,Allocator>::type;
template<
template<typename,typename> class PolyCollection,
typename T,typename OriginalAllocator,
template<typename> class Allocator
>
struct realloc_poly_collection_class<
PolyCollection<T,OriginalAllocator>,Allocator
>
{
using value_type=typename PolyCollection<T,OriginalAllocator>::value_type;
using type=PolyCollection<T,Allocator<value_type>>;
};
template<std::size_t N>
struct layout_data
{
std::array<const void*,N> datas;
std::array<std::size_t,N> sizes;
bool operator==(const layout_data& x)const
{
return datas==x.datas&&sizes==x.sizes;
}
};
template<typename... Types,typename PolyCollection>
layout_data<sizeof...(Types)> get_layout_data(const PolyCollection& p)
{
return{
{{(p.template is_registered<Types>()?
&*p.template begin<Types>():nullptr)...}},
{{(p.template is_registered<Types>()?
p.template size<Types>():0)...}}
};
}
} /* namespace test_utilities */
#endif