diff options
Diffstat (limited to 'src/boost/libs/assign')
21 files changed, 1984 insertions, 0 deletions
diff --git a/src/boost/libs/assign/Jamfile b/src/boost/libs/assign/Jamfile new file mode 100644 index 000000000..0914294b5 --- /dev/null +++ b/src/boost/libs/assign/Jamfile @@ -0,0 +1,10 @@ +# Boost.Assign Library Jamfile +# +# Copyright (c) 2018 James E. King III +# +# Use, modification, and distribution are subject to 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) + +# please order by name to ease maintenance +build-project test ; diff --git a/src/boost/libs/assign/LICENSE b/src/boost/libs/assign/LICENSE new file mode 100644 index 000000000..36b7cd93c --- /dev/null +++ b/src/boost/libs/assign/LICENSE @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/src/boost/libs/assign/README.md b/src/boost/libs/assign/README.md new file mode 100644 index 000000000..2356845b8 --- /dev/null +++ b/src/boost/libs/assign/README.md @@ -0,0 +1,33 @@ +Assign, part of collection of the [Boost C++ Libraries](http://github.com/boostorg), makes it easy to fill containers with data by overloading operator() and operator()(). + +### License + +Distributed under the [Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt). + +### Properties + +* C++03 +* Header Only + +### Build Status + +Branch | Travis | Appveyor | Coverity Scan | codecov.io | Deps | Docs | Tests | +:-------------: | ------ | -------- | ------------- | ---------- | ---- | ---- | ----- | +[`master`](https://github.com/boostorg/assign/tree/master) | [![Build Status](https://travis-ci.org/boostorg/assign.svg?branch=master)](https://travis-ci.org/boostorg/assign) | [![Build status](https://ci.appveyor.com/api/projects/status/a8pip7fvp609f0v2/branch/master?svg=true)](https://ci.appveyor.com/project/jeking3/assign-4i3tt/branch/master) | [![Coverity Scan Build Status](https://scan.coverity.com/projects/16318/badge.svg)](https://scan.coverity.com/projects/boostorg-assign) | [![codecov](https://codecov.io/gh/boostorg/assign/branch/master/graph/badge.svg)](https://codecov.io/gh/boostorg/assign/branch/master)| [![Deps](https://img.shields.io/badge/deps-master-brightgreen.svg)](https://pdimov.github.io/boostdep-report/master/assign.html) | [![Documentation](https://img.shields.io/badge/docs-master-brightgreen.svg)](http://www.boost.org/doc/libs/master/doc/html/assign.html) | [![Enter the Matrix](https://img.shields.io/badge/matrix-master-brightgreen.svg)](http://www.boost.org/development/tests/master/developer/assign.html) +[`develop`](https://github.com/boostorg/assign/tree/develop) | [![Build Status](https://travis-ci.org/boostorg/assign.svg?branch=develop)](https://travis-ci.org/boostorg/assign) | [![Build status](https://ci.appveyor.com/api/projects/status/a8pip7fvp609f0v2/branch/develop?svg=true)](https://ci.appveyor.com/project/jeking3/assign-4i3tt/branch/develop) | [![Coverity Scan Build Status](https://scan.coverity.com/projects/16318/badge.svg)](https://scan.coverity.com/projects/boostorg-assign) | [![codecov](https://codecov.io/gh/boostorg/assign/branch/develop/graph/badge.svg)](https://codecov.io/gh/boostorg/assign/branch/develop) | [![Deps](https://img.shields.io/badge/deps-develop-brightgreen.svg)](https://pdimov.github.io/boostdep-report/develop/assign.html) | [![Documentation](https://img.shields.io/badge/docs-develop-brightgreen.svg)](http://www.boost.org/doc/libs/develop/doc/html/assign.html) | [![Enter the Matrix](https://img.shields.io/badge/matrix-develop-brightgreen.svg)](http://www.boost.org/development/tests/develop/developer/assign.html) + +### Directories + +| Name | Purpose | +| ----------- | ------------------------------ | +| `doc` | documentation | +| `include` | headers | +| `test` | unit tests | + +### More information + +* [Ask questions](http://stackoverflow.com/questions/ask?tags=c%2B%2B,boost,boost-assign) +* [Report bugs](https://github.com/boostorg/assign/issues): Be sure to mention Boost version, platform and compiler you're using. A small compilable code sample to reproduce the problem is always good as well. +* Submit your patches as pull requests against **develop** branch. Note that by submitting patches you agree to license your modifications under the [Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt). +* Discussions about the library are held on the [Boost developers mailing list](http://www.boost.org/community/groups.html#main). Be sure to read the [discussion policy](http://www.boost.org/community/policy.html) before posting and add the `[assign]` tag at the beginning of the subject line. + diff --git a/src/boost/libs/assign/index.html b/src/boost/libs/assign/index.html new file mode 100644 index 000000000..001f41083 --- /dev/null +++ b/src/boost/libs/assign/index.html @@ -0,0 +1,24 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> + +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> +<meta http-equiv="refresh" content="0; URL=doc/index.html"> +<title>Boost.Assign Documentation</title> +<link rel="stylesheet" href="doc/style.css" type="text/css"> +</head> + +<body> +Automatic redirection failed, please go to +<a href="doc/index.html">doc/index.html</a> + <p> + Copyright © 2003-2007 Thorsten Ottosen. Use, modification and distribution is + subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt) + (See accompanying +file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy +at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>) + </p> +</body> +</html></body> + +</html> diff --git a/src/boost/libs/assign/meta/libraries.json b/src/boost/libs/assign/meta/libraries.json new file mode 100644 index 000000000..a78e091bb --- /dev/null +++ b/src/boost/libs/assign/meta/libraries.json @@ -0,0 +1,14 @@ +{ + "key": "assign", + "name": "Assign", + "authors": [ + "Thorsten Ottosen" + ], + "description": "Filling containers with constant or generated data has never been easier.", + "category": [ + "IO" + ], + "maintainers": [ + "Thorsten Ottosen <nesotto -at- cs.auc.dk>" + ] +} diff --git a/src/boost/libs/assign/test/Jamfile.v2 b/src/boost/libs/assign/test/Jamfile.v2 new file mode 100644 index 000000000..7172745ed --- /dev/null +++ b/src/boost/libs/assign/test/Jamfile.v2 @@ -0,0 +1,75 @@ +# Boost.Assign library +# +# Copyright Thorsten Ottosen 2003-2005. Use, modification and +# distribution is subject to 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) +# +# For more information, see http://www.boost.org/libs/assign/ +# + +import path ; +import regex ; + +rule assign-test ( name ) +{ + return [ + run $(name).cpp /boost/test//boost_unit_test_framework/<link>static ] + ; +} + +# this rule enumerates through all the headers and ensures +# that inclusion of the header by itself is sufficient to +# compile successfully, proving the header does not depend +# on any other headers to be included first - adapted from +# logic in the winapi test bjam script +rule test_headers +{ + local all_rules = ; + local file ; + local headers_path = [ path.make $(BOOST_ROOT)/libs/assign/include/boost/assign ] ; + for file in [ path.glob-tree $(headers_path) : *.hpp : assign ] + { + local rel_file = [ path.relative-to $(headers_path) $(file) ] ; + # Note: The test name starts with '~' in order to group these tests in the test report table, preferably at the end. + # All '/' are replaced with '-' because apparently test scripts have a problem with test names containing slashes. + local test_name = [ regex.replace $(rel_file) "/" "-" ] ; + local decl_test_name = ~hdr-decl-$(test_name) ; + # ECHO $(rel_file) ; + all_rules += [ compile compile/decl_header.cpp : <define>"BOOST_ASSIGN_TEST_HEADER=$(rel_file)" <dependency>$(file) : $(decl_test_name) ] ; + } + + local tests_path = [ path.make $(BOOST_ROOT)/libs/assign/test/compile-fail ] ; + for file in [ path.glob-tree $(tests_path) : *.cpp ] + { + local rel_file = [ path.relative-to $(tests_path) $(file) ] ; + local test_name = [ regex.replace [ regex.replace $(rel_file) "/" "-" ] ".cpp" "" ] ; + local decl_test_name = cf-$(test_name) ; + # ECHO $(rel_file) ; + all_rules += [ compile-fail $(file) : : $(decl_test_name) ] ; + } + + # ECHO All rules: $(all_rules) ; + return $(all_rules) ; +} + + +test-suite assign : + [ test_headers ] + [ assign-test basic ] + [ assign-test std ] + [ assign-test array ] + [ assign-test list_of ] + [ assign-test ptr_list_of ] + [ assign-test static_list_of ] + [ assign-test tuple_list_of ] + [ assign-test list_inserter ] + [ assign-test ptr_list_inserter ] + [ assign-test ptr_map_inserter ] + [ assign-test list_of_workaround ] + [ assign-test email_example ] + [ assign-test my_vector_example ] + [ assign-test multi_index_container ] + ; + + diff --git a/src/boost/libs/assign/test/array.cpp b/src/boost/libs/assign/test/array.cpp new file mode 100644 index 000000000..1723f612a --- /dev/null +++ b/src/boost/libs/assign/test/array.cpp @@ -0,0 +1,107 @@ +// Boost.Assign library +// +// Copyright Thorsten Ottosen 2003-2004. Use, modification and +// distribution is subject to 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) +// +// For more information, see http://www.boost.org/libs/assign/ +// + +#include <boost/detail/workaround.hpp> + +#if BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT(0x564) ) +# pragma warn -8091 // suppress warning in Boost.Test +# pragma warn -8057 // unused argument argc/argv in Boost.Test +#endif + +#include <boost/assign/list_of.hpp> +#include <boost/array.hpp> +#include <boost/test/test_tools.hpp> +#include <iostream> +#include <algorithm> +#include <iterator> + +#ifndef BOOST_NO_CXX11_HDR_ARRAY +#include <array> + +void check_std_array() +{ + using namespace boost::assign; + + typedef std::array<float,6> Array; + + Array a = list_of(1)(2)(3)(4)(5)(6); + + BOOST_CHECK_EQUAL( a[0], 1 ); + BOOST_CHECK_EQUAL( a[5], 6 ); + // last element is implicitly 0 + Array a2 = list_of(1)(2)(3)(4)(5); + BOOST_CHECK_EQUAL( a2[5], 0 ); + // two last elements are implicitly + a2 = list_of(1)(2)(3)(4); + BOOST_CHECK_EQUAL( a2[4], 0 ); + BOOST_CHECK_EQUAL( a2[5], 0 ); + // too many arguments + BOOST_CHECK_THROW( a2 = list_of(1)(2)(3)(4)(5)(6)(7), assignment_exception ); +} + +#endif + +void check_array() +{ + using namespace boost::assign; + + typedef boost::array<float,6> Array; + + +#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) + Array a = list_of(1)(2)(3)(4)(5)(6).to_array(a); +#else + Array a = list_of(1)(2)(3)(4)(5)(6); +#endif + + BOOST_CHECK_EQUAL( a[0], 1 ); + BOOST_CHECK_EQUAL( a[5], 6 ); + // last element is implicitly 0 +#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) + Array a2 = list_of(1)(2)(3)(4)(5).to_array(a2); +#else + Array a2 = list_of(1)(2)(3)(4)(5); +#endif + BOOST_CHECK_EQUAL( a2[5], 0 ); + // two last elements are implicitly +#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) + a2 = list_of(1))(2)(3)(4).to_array(a2); +#else + a2 = list_of(1)(2)(3)(4); +#endif + BOOST_CHECK_EQUAL( a2[4], 0 ); + BOOST_CHECK_EQUAL( a2[5], 0 ); + // too many arguments +#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) + + BOOST_CHECK_THROW( a2 = list_of(1)(2)(3)(4)(5)(6)(6).to_array(a2), + assignment_exception ); +#else + BOOST_CHECK_THROW( a2 = list_of(1)(2)(3)(4)(5)(6)(7), assignment_exception ); +#endif +} + + +#include <boost/test/unit_test.hpp> +using boost::unit_test::test_suite; + + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); + + test->add( BOOST_TEST_CASE( &check_array ) ); +#ifndef BOOST_NO_CXX11_HDR_ARRAY + test->add( BOOST_TEST_CASE( &check_std_array ) ); +#endif + + return test; +} + diff --git a/src/boost/libs/assign/test/basic.cpp b/src/boost/libs/assign/test/basic.cpp new file mode 100644 index 000000000..077823d64 --- /dev/null +++ b/src/boost/libs/assign/test/basic.cpp @@ -0,0 +1,47 @@ +// Boost.Assign library +// +// Copyright Thorsten Ottosen 2003-2004. Use, modification and +// distribution is subject to 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) +// +// For more information, see http://www.boost.org/libs/assign/ +// + +#include <boost/detail/workaround.hpp> + +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +# pragma warn -8091 // suppress warning in Boost.Test +# pragma warn -8057 // unused argument argc/argv in Boost.Test +#endif + +#include <boost/assign/std/vector.hpp> +#include <boost/assign/std/map.hpp> +#include <string> + + +using namespace boost::assign; + +void check_basic_usage() +{ + std::vector<int> v; + v += 1,2,3,4,5,6,7,8,9; + push_back( v )(10)(11); + std::map<std::string,int> m; + insert( m )( "foo", 1 )( "bar", 2 ); +} + + + +#include <boost/test/unit_test.hpp> +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Assign Test Suite" ); + + test->add( BOOST_TEST_CASE( &check_basic_usage ) ); + + return test; +} + diff --git a/src/boost/libs/assign/test/compile/decl_header.cpp b/src/boost/libs/assign/test/compile/decl_header.cpp new file mode 100644 index 000000000..9f75774b5 --- /dev/null +++ b/src/boost/libs/assign/test/compile/decl_header.cpp @@ -0,0 +1,24 @@ +/* + * Copyright Andrey Semashev 2015. + * 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) + */ +/*! + * \file decl_header.cpp + * \author Andrey Semashev + * \date 21.06.2015 + * + * \brief This file contains a test boilerplate for checking that every + * public header is self-contained and does not have any missing + * #includes. + */ + +#define BOOST_ASSIGN_TEST_INCLUDE_HEADER() <boost/assign/BOOST_ASSIGN_TEST_HEADER> + +#include BOOST_ASSIGN_TEST_INCLUDE_HEADER() + +int main(int, char*[]) +{ + return 0; +} diff --git a/src/boost/libs/assign/test/email_example.cpp b/src/boost/libs/assign/test/email_example.cpp new file mode 100644 index 000000000..3e8b98ba0 --- /dev/null +++ b/src/boost/libs/assign/test/email_example.cpp @@ -0,0 +1,155 @@ +// Boost.Assign library +// +// Copyright Thorsten Ottosen 2003-2004. Use, modification and +// distribution is subject to 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) +// +// For more information, see http://www.boost.org/libs/assign/ +// + + +#include <boost/detail/workaround.hpp> + +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +# pragma warn -8091 // suppress warning in Boost.Test +# pragma warn -8057 // unused argument argc/argv in Boost.Test +#endif + +#include <boost/assign/list_inserter.hpp> +#include <boost/test/test_tools.hpp> +#include <boost/function.hpp> +#include <boost/bind.hpp> +#include <vector> +#include <map> + +namespace ba = boost::assign; + +class email +{ +public: + enum address_option + { + check_addr_book, + dont_check_addr_book + }; + + typedef std::pair<std::string,address_option> bcc_type; + typedef std::vector< bcc_type > bcc_map; + typedef std::map<std::string,address_option> address_map; + + +private: + + mutable address_map cc_list; + mutable address_map to_list; + bcc_map bcc_list; + + struct add_to_map + { + address_map& m; + + add_to_map( address_map& m ) : m(m) + {} + + void operator()( const std::string& name, address_option ao ) + { + m[ name ] = ao; + } + + void operator()( const std::string& name ) + { + m[ name ] = check_addr_book; + } + }; + + struct add_to_vector + { + bcc_map& m; + + add_to_vector( bcc_map& m ) : m(m) + {} + + void operator()( const bcc_type& r ) + { + m.push_back( r ); + } + }; + +public: + + ba::list_inserter< add_to_map > + add_cc( std::string name, address_option ao ) + { + return ba::make_list_inserter( add_to_map( cc_list ) )( name, ao ); + } + + ba::list_inserter< add_to_map > + add_to( const std::string& name ) + { + return ba::make_list_inserter( add_to_map( to_list ) )( name ); + } + + ba::list_inserter< add_to_vector, bcc_type > + add_bcc( const bcc_type& bcc ) + { + return ba::make_list_inserter( add_to_vector( bcc_list ) )( bcc ); + } + + address_option + cc_at( const std::string& name ) const + { + return cc_list[ name ]; + } + + address_option + to_at( const std::string& name ) const + { + return to_list[ name ]; + } + + address_option + bcc_at( unsigned index ) const + { + return bcc_list.at( index ).second; + } +}; + + + +void check_list_inserter() +{ + using namespace boost::assign; + + email e; + e.add_cc( "franz", email::dont_check_addr_book ) + ( "hanz", email::check_addr_book ) + ( "betty", email::dont_check_addr_book ); + BOOST_CHECK_EQUAL( e.cc_at( "franz" ), email::dont_check_addr_book ); + BOOST_CHECK_EQUAL( e.cc_at( "hanz" ), email::check_addr_book ); + BOOST_CHECK_EQUAL( e.cc_at( "betty" ), email::dont_check_addr_book ); + + e.add_to( "betsy" )( "peter" ); + BOOST_CHECK_EQUAL( e.cc_at( "betsy" ), email::check_addr_book ); + BOOST_CHECK_EQUAL( e.cc_at( "peter" ), email::check_addr_book ); + + e.add_bcc( email::bcc_type( "Mr. Foo", email::check_addr_book ) ) + ( "Mr. Bar", email::dont_check_addr_book ); + BOOST_CHECK_EQUAL( e.bcc_at( 0 ), email::check_addr_book ); + BOOST_CHECK_EQUAL( e.bcc_at( 1 ), email::dont_check_addr_book ); + +} + + +#include <boost/test/unit_test.hpp> +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); + + test->add( BOOST_TEST_CASE( &check_list_inserter ) ); + + return test; +} + diff --git a/src/boost/libs/assign/test/list_inserter.cpp b/src/boost/libs/assign/test/list_inserter.cpp new file mode 100644 index 000000000..8d904764b --- /dev/null +++ b/src/boost/libs/assign/test/list_inserter.cpp @@ -0,0 +1,158 @@ +// Boost.Assign library +// +// Copyright Thorsten Ottosen 2003-2004. Use, modification and +// distribution is subject to 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) +// +// For more information, see http://www.boost.org/libs/assign/ +// + +#include <boost/detail/workaround.hpp> + +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +# pragma warn -8091 // suppress warning in Boost.Test +# pragma warn -8057 // unused argument argc/argv in Boost.Test +#endif + + +#include <boost/assign/list_inserter.hpp> +#include <boost/assign/list_of.hpp> +#include <boost/test/test_tools.hpp> +#include <boost/array.hpp> +#include <boost/function.hpp> +#include <boost/bind.hpp> +#include <boost/functional.hpp> +#include <iostream> +#include <vector> +#include <map> +#include <string> +#include <utility> +#include <stdexcept> +#include <cstdlib> + + +namespace ba = boost::assign; + +void function_ptr( int ) +{ + // do nothing +} + +struct functor +{ + template< class T > + void operator()( T ) const + { + // do nothing + } +}; + + + +void check_list_inserter() +{ + using namespace std; + using namespace boost; + using namespace boost::assign; + vector<int> v; + + // + // @note: cast only necessary on CodeWarrior + // + make_list_inserter( (void (*)(int))&function_ptr )( 5 ),3; + make_list_inserter( functor() )( 4 ),2; + + typedef void (vector<int>::* push_back_t)(const int&); + push_back_t push_back_func = &vector<int>::push_back; + make_list_inserter( boost::bind( push_back_func, &v, _1 ) )( 6 ),4; + + BOOST_CHECK_EQUAL( v.size(), 2u ); + BOOST_CHECK_EQUAL( v[0], 6 ); + BOOST_CHECK_EQUAL( v[1], 4 ); + + push_back( v ) = 1,2,3,4,5; + BOOST_CHECK_EQUAL( v.size(), 7u ); + BOOST_CHECK_EQUAL( v[6], 5 ); + + push_back( v )(6).repeat( 10, 7 )(8); + BOOST_CHECK_EQUAL( v.size(), 19u ); + BOOST_CHECK_EQUAL( v[18], 8 ); + BOOST_CHECK_EQUAL( v[8], 7 ); + BOOST_CHECK_EQUAL( v[16], 7 ); + +#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1200) + push_back( v ) = repeat_fun( 10, &rand ); +#else + push_back( v ).repeat_fun( 10, &rand ); +#endif + + BOOST_CHECK_EQUAL( v.size(), 29u ); + +#if BOOST_WORKAROUND(BOOST_MSVC, <= 1200) || BOOST_WORKAROUND(__SUNPRO_CC, <= 0x580 ) + push_back( v )(1).repeat( 10, 2 )(3); +#else + push_back( v ) = 1,repeat( 10, 2 ),3; +#endif + BOOST_CHECK_EQUAL( v.size(), 41u ); + +#if BOOST_WORKAROUND(BOOST_MSVC, <= 1200) || BOOST_WORKAROUND(__SUNPRO_CC, <= 0x580 ) + push_back( v )(1).repeat_fun( 10, &rand )(2); +#else + push_back( v ) = 1,repeat_fun( 10, &rand ),2; +#endif + + BOOST_CHECK_EQUAL( v.size(), 53u ); + + typedef map<string,int> map_t; + typedef map_t::value_type V; + map_t m; + + make_list_inserter( assign_detail::call_insert< map_t >( m ) ) + ( V("bar",3) )( V("foo", 2) ); + BOOST_CHECK_EQUAL( m.size(), 2u ); + BOOST_CHECK_EQUAL( m["foo"], 2 ); + + +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) \ + || BOOST_WORKAROUND(BOOST_MSVC, <=1300) \ + || BOOST_WORKAROUND(BOOST_MSVC, ==1700) \ + || !defined( BOOST_NO_CXX11_HDR_INITIALIZER_LIST ) +#else + + typedef vector<int> score_type; + typedef map<string,score_type> team_score_map; + typedef std::pair<string,score_type> score_pair; + team_score_map team_score; + insert( team_score )( "Team Foo", list_of(1)(1)(0) ) + ( "Team Bar", list_of(0)(0)(0) ) + ( "Team FooBar", list_of(0)(0)(1) ); + BOOST_CHECK_EQUAL( team_score.size(), 3u ); + BOOST_CHECK_EQUAL( team_score[ "Team Foo" ][1], 1 ); + BOOST_CHECK_EQUAL( team_score[ "Team Bar" ][0], 0 ); + + team_score = list_of< score_pair > + ( "Team Foo", list_of(1)(1)(0) ) + ( "Team Bar", list_of(0)(0)(0) ) + ( "Team FooBar", list_of(0)(0)(1) ); + BOOST_CHECK_EQUAL( team_score.size(), 3u ); + BOOST_CHECK_EQUAL( team_score[ "Team Foo" ][1], 1 ); + BOOST_CHECK_EQUAL( team_score[ "Team Bar" ][0], 0 ); +#endif + +} + + + +#include <boost/test/unit_test.hpp> +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); + + test->add( BOOST_TEST_CASE( &check_list_inserter ) ); + + return test; +} + diff --git a/src/boost/libs/assign/test/list_of.cpp b/src/boost/libs/assign/test/list_of.cpp new file mode 100644 index 000000000..b5bc0ed09 --- /dev/null +++ b/src/boost/libs/assign/test/list_of.cpp @@ -0,0 +1,309 @@ +// Boost.Assign library +// +// Copyright Thorsten Ottosen 2003-2004. Use, modification and +// distribution is subject to 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) +// +// For more information, see http://www.boost.org/libs/assign/ +// + + +#include <boost/detail/workaround.hpp> + +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +# pragma warn -8091 // suppress warning in Boost.Test +# pragma warn -8057 // unused argument argc/argv in Boost.Test +#endif + +#include <boost/assign/list_of.hpp> +#include <boost/test/test_tools.hpp> +#include <boost/array.hpp> +#include <algorithm> +#include <vector> +#include <list> +#include <deque> +#include <set> +#include <map> +#include <stack> +#include <string> +#include <cstdlib> +#include <complex> + +struct nothing +{ + template< class T > + void operator()( T ) + { } + +}; + +template< class Range > +void for_each( const Range& r ) +{ + std::for_each( r.begin(), r.end(), nothing() ); +} + +namespace ba = boost::assign; + +template< class C > +void test_sequence_list_of_string() +{ +#if BOOST_WORKAROUND(BOOST_MSVC, <=1300) + const C c = ba::list_of( "foo" )( "bar" ).to_container( c ); +#else + const C c = ba::list_of( "foo" )( "bar" ); +#endif + BOOST_CHECK_EQUAL( c.size(), 2u ); +} + +struct parameter_list +{ + int val; + + template< class T > + parameter_list( T ) + : val(0) + { } + + template< class T > + parameter_list( const T&, int ) + : val(1) + { } +}; + +template< class C > +void test_sequence_list_of_int() +{ + using namespace std; +#if BOOST_WORKAROUND(BOOST_MSVC, <=1300) + + const C c = ba::list_of<int>(1)(2)(3)(4).to_container( c ); + const C c2 = ba::list_of(1)(2)(3)(4).to_container( c2 ); + BOOST_CHECK_EQUAL( c.size(), 4u ); + BOOST_CHECK_EQUAL( c2.size(), 4u ); + C c3 = ba::list_of(1).repeat( 1, 2 )(3).to_container( c3 ); + BOOST_CHECK_EQUAL( c3.size(), 3u ); + + c3 = ba::list_of(1).repeat_fun( 10, &rand )(2)(3).to_container( c3 ); + BOOST_CHECK_EQUAL( c3.size(), 13u ); + +#else + + const C c = ba::list_of<int>(1)(2)(3)(4); + const C c2 = ba::list_of(1)(2)(3)(4); + BOOST_CHECK_EQUAL( c.size(), 4u ); + BOOST_CHECK_EQUAL( c2.size(), 4u ); + C c3 = ba::list_of(1).repeat( 1, 2 )(3); + BOOST_CHECK_EQUAL( c3.size(), 3u ); + +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) + // BCB fails to use operator=() directly, + // it must be worked around using e.g. auxiliary variable + C aux = ba::list_of(1).repeat_fun( 10, &rand )(2)(3); + BOOST_CHECK_EQUAL( aux.size(), 13u ); + c3 = aux; + BOOST_CHECK_EQUAL( c3.size(), 13u ); +#elif defined( BOOST_NO_CXX11_HDR_INITIALIZER_LIST ) + c3 = ba::list_of(1).repeat_fun( 10, &rand )(2)(3); + BOOST_CHECK_EQUAL( c3.size(), 13u ); +#endif + +#if !defined( BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS ) + C c4; + c4 = ba::list_of(1)(2)(3)(4); + BOOST_CHECK_EQUAL( c4.size(), 4u ); + C c5(ba::list_of(1)(2)(3)(4)(5)); + BOOST_CHECK_EQUAL( c5.size(), 5u ); +#endif + +#endif + + parameter_list p( ba::list_of(1)(2), 3u ); + BOOST_CHECK_EQUAL( p.val, 1 ); + +} + +template< class C > +void test_map_list_of() +{ + const C c = ba::list_of< std::pair<std::string,int> >( "foo", 1 )( "bar", 2 )( "buh", 3 )( "bah", 4 ); + BOOST_CHECK_EQUAL( c.size(), 4u ); + const C c2 = ba::map_list_of( "foo", 1 )( "bar", 2 )( "buh", 3 )( "bah", 4 ); + BOOST_CHECK_EQUAL( c2.size(), 4u ); +} + +void test_vector_matrix() +{ + using namespace boost; + using namespace boost::assign; + using namespace std; + using boost::array; + +#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(BOOST_MSVC, <=1300) +#else + + const int sz = 3; + typedef array<int,sz> row3; + typedef array<row3,sz> matrix3x3; + + + matrix3x3 m = list_of( list_of(1)(2)(3) ) + ( list_of(4)(5)(6) ) + ( list_of(7)(8)(9) ); + + for( int i = 0; i != sz; ++i ) + for( int j = 0; j != sz; ++j ) + BOOST_CHECK_EQUAL( m[i][j], i*sz + j + 1 ); + + typedef vector<int> row; + typedef vector<row> matrix; + + // + // note: some libraries need a little help + // with the conversion, hence the 'row' template parameter. + // + matrix m2 = list_of< row >( list_of(1)(2)(3) ) + ( list_of(4)(5) ) + ( list_of(6) ); + + for( int i = 0; i != sz; ++i ) + for( int j = 0; j != sz - i; ++j ) + BOOST_CHECK_EQUAL( m[i][j], i*sz + j + 1 ); + +#endif + +} + +void test_map_list_of() +{ +/* + maybe in the future... + + using namespace std; + using namespace boost::assign; + + typedef vector<int> score_type; + typedef map<string,score_type> team_score_map; + + team_score_map team_score = map_list_of + ( "Team Foo", list_of(1)(1)(0) ) + ( "Team Bar", list_of(0)(0)(0) ) + ( "Team FooBar", list_of(0)(0)(1) ); + BOOST_CHECK_EQUAL( team_score.size(), 3 ); + BOOST_CHECK_EQUAL( team_score[ "Team Foo" ][1], 1 ); + BOOST_CHECK_EQUAL( team_score[ "Team Bar" ][0], 0 ); +*/ + +} + +/* +void test_complex_list_of() +{ + typedef std::complex<float> complex_t; + std::vector<complex_t> v; + v = ba::list_of<complex_t>(1,2)(2,3)(4,5)(0). + repeat_from_to( complex_t(0,0), complex_t(10,10), complex_t(1,1) ); +} +*/ + +struct five +{ + five( int, int, int, int, int ) + { + } +}; + +void test_list_of() +{ + ba::list_of< five >(1,2,3,4,5)(6,7,8,9,10); + +/* Maybe this could be useful in a later version? + + // an anonymous lists, fulfills Range concept + for_each( ba::list_of( T() )( T() )( T() ) ); + + // non-anonymous lists + ba::generic_list<T> list_1 = ba::list_of( T() ); + BOOST_CHECK_EQUAL( list_1.size(), 1 ); + ba::generic_list<T> list_2 = list_1 + ba::list_of( T() )( T() ) + list_1; + BOOST_CHECK_EQUAL( list_2.size(), 4 ); + list_1 += list_2; + BOOST_CHECK_EQUAL( list_1.size(), 5 ); +*/ +} + +// +// @remark: ADL is required here, but it is a bit weird to +// open up namespace std. Perhaps Boost.Test needs a +// better configuration option. +// +namespace std +{ + template< class T, class Elem, class Traits > + inline std::basic_ostream<Elem,Traits>& + operator<<( std::basic_ostream<Elem, Traits>& Os, + const std::vector<T>& r ) + { + return Os << ::boost::make_iterator_range( r.begin(), r.end() ); + } +} + +template <class Seq> +inline std::vector<int> as_seq( const Seq& s ) +{ + std::vector<int> c; + return s.to_container( c ); +} + +void test_comparison_operations() +{ + BOOST_CHECK_EQUAL( ba::list_of(0)(1)(2), as_seq(ba::list_of(0)(1)(2)) ); + BOOST_CHECK_NE( ba::list_of(0)(1)(2), as_seq(ba::list_of(-1)(1)(2)) ); + BOOST_CHECK_LT( ba::list_of(0)(1)(2), as_seq(ba::list_of(0)(1)(3)) ); + BOOST_CHECK_LE( ba::list_of(0)(1)(2), as_seq(ba::list_of(0)(1)(2)) ); + BOOST_CHECK_GT( ba::list_of(0)(1)(3), as_seq(ba::list_of(0)(1)(2)) ); + BOOST_CHECK_GE( ba::list_of(0)(1)(2), as_seq(ba::list_of(0)(1)(2)) ); + BOOST_CHECK_EQUAL( as_seq(ba::list_of(0)(1)(2)), ba::list_of(0)(1)(2) ); + BOOST_CHECK_NE( as_seq(ba::list_of(0)(1)(2)), ba::list_of(-1)(1)(2) ); + BOOST_CHECK_LT( as_seq(ba::list_of(0)(1)(2)), ba::list_of(0)(1)(3) ); + BOOST_CHECK_LE( as_seq(ba::list_of(0)(1)(2)), ba::list_of(0)(1)(2) ); + BOOST_CHECK_GT( as_seq(ba::list_of(0)(1)(3)), ba::list_of(0)(1)(2) ); + BOOST_CHECK_GE( as_seq(ba::list_of(0)(1)(2)), ba::list_of(0)(1)(2) ); +} + +void check_list_of() +{ + test_sequence_list_of_int< std::vector<int> >(); + test_sequence_list_of_int< std::list<int> >(); + test_sequence_list_of_int< std::deque<int> >(); + test_sequence_list_of_int< std::set<int> >(); + test_sequence_list_of_int< std::multiset<int> >(); + test_sequence_list_of_int< std::vector<float> >(); + + test_sequence_list_of_string< std::vector<std::string> >(); + + test_map_list_of< std::map<std::string,int> >(); + test_map_list_of< std::multimap<std::string,int> >(); + + std::stack<std::string> s = ba::list_of( "Foo" )( "Bar" )( "FooBar" ).to_adapter( s ); + test_list_of(); + test_vector_matrix(); + test_comparison_operations(); +} + + + +#include <boost/test/unit_test.hpp> +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); + + test->add( BOOST_TEST_CASE( &check_list_of ) ); + + return test; +} + + diff --git a/src/boost/libs/assign/test/list_of_workaround.cpp b/src/boost/libs/assign/test/list_of_workaround.cpp new file mode 100644 index 000000000..2e72e9304 --- /dev/null +++ b/src/boost/libs/assign/test/list_of_workaround.cpp @@ -0,0 +1,59 @@ +// Boost.Assign library +// +// Copyright Thorsten Ottosen 2003-2004. Use, modification and +// distribution is subject to 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) +// +// For more information, see http://www.boost.org/libs/assign/ +// + + +#include <boost/detail/workaround.hpp> + +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +# pragma warn -8091 // suppress warning in Boost.Test +# pragma warn -8057 // unused argument argc/argv in Boost.Test +#endif + +#include <boost/assign/list_of.hpp> +#include <boost/test/test_tools.hpp> +#include <vector> +#include <set> +#include <map> +#include <stack> +#include <queue> +#include <boost/array.hpp> + +void check_list_of() +{ + using namespace std; + using namespace boost; + using namespace boost::assign; + using boost::array; + + vector<int> v = list_of(1)(2)(3)(4).to_container( v ); + set<int> s = list_of(1)(2)(3)(4).to_container( s ); + map<int,int> m = map_list_of(1,2)(2,3).to_container( m ); + stack<int> st = list_of(1)(2)(3)(4).to_adapter( st ); + queue<int> q = list_of(1)(2)(3)(4).to_adapter( q ); + array<int,4> a = list_of(1)(2)(3)(4).to_array( a ); + const vector<int> v2 = list_of(1).to_container( v2 ); + const array<int,1> a2 = list_of(1).to_array( a2 ); +} + + + +#include <boost/test/unit_test.hpp> +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); + + test->add( BOOST_TEST_CASE( &check_list_of ) ); + + return test; +} + + diff --git a/src/boost/libs/assign/test/multi_index_container.cpp b/src/boost/libs/assign/test/multi_index_container.cpp new file mode 100644 index 000000000..711ba5d4d --- /dev/null +++ b/src/boost/libs/assign/test/multi_index_container.cpp @@ -0,0 +1,168 @@ +// Boost.Assign library +// +// Copyright Thorsten Ottosen 2003-2004. Use, modification and +// distribution is subject to 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) +// +// For more information, see http://www.boost.org/libs/assign/ +// + + +#include <boost/detail/workaround.hpp> + +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +# pragma warn -8091 // suppress warning in Boost.Test +# pragma warn -8057 // unused argument argc/argv in Boost.Test +#endif + +#include <boost/assign/list_of.hpp> +#include <boost/assign/list_inserter.hpp> +#include <boost/multi_index_container.hpp> +#include <boost/multi_index/identity.hpp> +#include <boost/multi_index/member.hpp> +#include <boost/multi_index/ordered_index.hpp> +#include <boost/multi_index/sequenced_index.hpp> +#include <boost/test/test_tools.hpp> +#include <boost/test/unit_test.hpp> +#include <cstddef> +#include <ostream> +#include <string> + +using namespace boost; +using namespace boost::multi_index; +namespace ba = boost::assign; + +// +// Define a classical multi_index_container for employees +// +struct employee +{ + int id; + std::string name; + int age; + + employee(int id_,std::string name_,int age_):id(id_),name(name_),age(age_){} + + bool operator==(const employee& x)const + { + return id==x.id&&name==x.name&&age==x.age; + } + + bool operator<(const employee& x)const + { + return id<x.id; + } + + bool operator!=(const employee& x)const{return !(*this==x);} + bool operator> (const employee& x)const{return x<*this;} + bool operator>=(const employee& x)const{return !(*this<x);} + bool operator<=(const employee& x)const{return !(x<*this);} + + struct comp_id + { + bool operator()(int x,const employee& e2)const{return x<e2.id;} + bool operator()(const employee& e1,int x)const{return e1.id<x;} + }; + + friend std::ostream& operator<<(std::ostream& os,const employee& e) + { + os<<e.id<<" "<<e.name<<" "<<e.age<<std::endl; + return os; + } +}; + +struct name{}; +struct by_name{}; +struct age{}; +struct as_inserted{}; + +typedef + multi_index_container< + employee, + indexed_by< + ordered_unique< + identity<employee> >, + ordered_non_unique< + tag<name,by_name>, + BOOST_MULTI_INDEX_MEMBER(employee,std::string,name)>, + ordered_non_unique< + tag<age>, + BOOST_MULTI_INDEX_MEMBER(employee,int,age)>, + sequenced< + tag<as_inserted> > > > + employee_set; + +#if defined(BOOST_NO_MEMBER_TEMPLATES) +typedef nth_index< + employee_set,1>::type employee_set_by_name; +#else +typedef employee_set::nth_index<1>::type employee_set_by_name; +#endif + +typedef boost::multi_index::index< + employee_set,age>::type employee_set_by_age; +typedef boost::multi_index::index< + employee_set,as_inserted>::type employee_set_as_inserted; + +// +// Define a multi_index_container with a list-like index and an ordered index +// +typedef multi_index_container< + std::string, + indexed_by< + sequenced<>, // list-like index + ordered_non_unique<identity<std::string> > // words by alphabetical order + > +> text_container; + + + +void test_multi_index_container() +{ + employee_set eset = ba::list_of< employee >(1,"Franz",30)(2,"Hanz",40)(3,"Ilse",50); + BOOST_CHECK( eset.size() == 3u ); + + // + // This container is associative, hence we can use 'insert()' + // + + ba::insert( eset )(4,"Kurt",55)(5,"Bjarne",77)(7,"Thorsten",24); + BOOST_CHECK( eset.size() == 6u ); + + employee_set_by_name& name_index = boost::multi_index::get<name>(eset); + employee_set_by_name::iterator i = name_index.find("Ilse"); + BOOST_CHECK( i->id == 3 ); + BOOST_CHECK( i->age == 50 ); + + text_container text = ba::list_of< std::string >("Have")("you")("ever")("wondered")("how")("much")("Boost")("rocks?!"); + BOOST_CHECK_EQUAL( text.size(), 8u ); + BOOST_CHECK_EQUAL( *text.begin(), "Have" ); + + // + // This container is a sequence, hence we can use 'push_back()' and 'push_font()' + // + + ba::push_back( text )("Well")(",")("A")("LOT")(",")("obviously!"); + BOOST_CHECK_EQUAL( text.size(), 14u ); + BOOST_CHECK_EQUAL( *--text.end(), "obviously!" ); + + ba::push_front( text ) = "question:", "simple", "A"; + BOOST_CHECK_EQUAL( text.size(), 17u ); + BOOST_CHECK_EQUAL( text.front(), "A" ); +} + + + +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); + + test->add( BOOST_TEST_CASE( &test_multi_index_container ) ); + + return test; +} + + diff --git a/src/boost/libs/assign/test/my_vector_example.cpp b/src/boost/libs/assign/test/my_vector_example.cpp new file mode 100644 index 000000000..f1a1849ce --- /dev/null +++ b/src/boost/libs/assign/test/my_vector_example.cpp @@ -0,0 +1,115 @@ +// Boost.Assign library +// +// Copyright Thorsten Ottosen 2003-2004. Use, modification and +// distribution is subject to 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) +// +// For more information, see http://www.boost.org/libs/assign/ +// + + +#include <boost/detail/workaround.hpp> + +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +# pragma warn -8091 // suppress warning in Boost.Test +# pragma warn -8057 // unused argument argc/argv in Boost.Test +#endif + +#include <boost/assign/list_inserter.hpp> +#include <boost/test/test_tools.hpp> +#include <boost/function.hpp> +#include <boost/bind.hpp> +#include <vector> +#include <stdexcept> + +namespace ba = boost::assign; + + + +template< class C > +class range_inserter +{ + typedef typename C::iterator iterator; + iterator begin, end; +public: + range_inserter( C& c ) + : begin( c.begin() ), end( c.end() ) + { } + + template< class T > + void operator()( T r ) + { + if( begin == end ) + throw std::range_error( "range error: <range_inserter>" ); + *begin = r; + ++begin; + } +}; + + + +template< class C > +inline range_inserter<C> make_range_inserter( C& c ) +{ + return range_inserter<C>( c ); +} + + + +template< class T > +class my_vector +{ + typedef std::vector<T> vector_t; + typedef typename vector_t::size_type size_type; + vector_t data_; + +public: + my_vector() : data_( 10, 0 ) + { } + + ba::list_inserter< range_inserter< vector_t >, T > + operator=( T r ) + { + return ba::make_list_inserter( make_range_inserter( data_ ) )( r ); + } + + size_type size() const + { + return data_.size(); + } + + const T& operator[]( size_type index ) + { + return data_.at( index ); + } +}; + + + +void check_list_inserter() +{ + using namespace std; + using namespace boost::assign; + + my_vector<int> vec; + vec = 1,2,3,4,5,6,7,8,9,10; + BOOST_CHECK_EQUAL( vec.size(), 10u ); + BOOST_CHECK_EQUAL( vec[0], 1 ); + BOOST_CHECK_EQUAL( vec[9], 10 ); +} + + + +#include <boost/test/unit_test.hpp> +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); + + test->add( BOOST_TEST_CASE( &check_list_inserter ) ); + + return test; +} + diff --git a/src/boost/libs/assign/test/ptr_list_inserter.cpp b/src/boost/libs/assign/test/ptr_list_inserter.cpp new file mode 100644 index 000000000..ddfd57cda --- /dev/null +++ b/src/boost/libs/assign/test/ptr_list_inserter.cpp @@ -0,0 +1,106 @@ +// Boost.Assign library +// +// Copyright Thorsten Ottosen 2003-2006. Use, modification and +// distribution is subject to 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) +// +// For more information, see http://www.boost.org/libs/assign/ +// + +#include <boost/detail/workaround.hpp> + +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +# pragma warn -8091 // suppress warning in Boost.Test +# pragma warn -8057 // unused argument argc/argv in Boost.Test +#endif + + +#include <boost/assign/ptr_list_inserter.hpp> +#include <boost/test/test_tools.hpp> +#include <boost/ptr_container/ptr_deque.hpp> +#include <boost/ptr_container/ptr_set.hpp> +#include <typeinfo> + +struct Foo +{ + int i; + + Foo() : i(0) + { } + Foo( int i ) : i(i) + { } + Foo( int i, int ) : i(i) + { } + Foo( const char*, int i, int ) : i(i) + { } + + virtual ~Foo() + { } +}; + +struct FooBar : Foo +{ + FooBar( int i ) : Foo(i) + { } + + FooBar( int i, const char* ) + { } +}; + +inline bool operator<( const Foo& l, const Foo& r ) +{ + return l.i < r.i; +} + +void check_ptr_list_inserter() +{ + using namespace std; + using namespace boost; + using namespace boost::assign; + + ptr_deque<Foo> deq; + ptr_push_back( deq )()(); + BOOST_CHECK( deq.size() == 2u ); + + ptr_push_front( deq )( 3 )( 42, 42 )( "foo", 42, 42 ); + BOOST_CHECK( deq.size() == 5u ); + + ptr_set<Foo> a_set; + ptr_insert( a_set )()( 1 )( 2, 2 )( "foo", 3, 3 ); + BOOST_CHECK( a_set.size() == 4u ); + ptr_insert( a_set )()()()(); + BOOST_CHECK( a_set.size() == 4u ); // duplicates not inserted + +#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING + + ptr_push_back<FooBar>( deq )( 42, "42" ); + BOOST_CHECK_EQUAL( deq.size(), 6u ); + BOOST_CHECK( typeid(deq[5u]) == typeid(FooBar) ); + + ptr_push_front<FooBar>( deq )( 42, "42" ); + BOOST_CHECK_EQUAL( deq.size(), 7u ); + BOOST_CHECK( typeid(deq[0]) == typeid(FooBar) ); + + ptr_insert<FooBar>( a_set )( 4 ); + BOOST_CHECK( a_set.size() == 5u ); + BOOST_CHECK( typeid(*--a_set.end()) == typeid(FooBar) ); + +#endif + +} + + + +#include <boost/test/unit_test.hpp> +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); + + test->add( BOOST_TEST_CASE( &check_ptr_list_inserter ) ); + + return test; +} + diff --git a/src/boost/libs/assign/test/ptr_list_of.cpp b/src/boost/libs/assign/test/ptr_list_of.cpp new file mode 100644 index 000000000..9f59f03ec --- /dev/null +++ b/src/boost/libs/assign/test/ptr_list_of.cpp @@ -0,0 +1,75 @@ +// Boost.Assign library +// +// Copyright Thorsten Ottosen 2003-2004. Use, modification and +// distribution is subject to 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) +// +// For more information, see http://www.boost.org/libs/assign/ +// + + +#include <boost/detail/workaround.hpp> + +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +# pragma warn -8091 // suppress warning in Boost.Test +# pragma warn -8057 // unused argument argc/argv in Boost.Test +#endif + +#include <boost/assign/ptr_list_of.hpp> +#include <boost/test/test_tools.hpp> +#include <boost/ptr_container/ptr_container.hpp> + +struct Foo +{ + int i; + + Foo() : i(0) + { } + Foo( int i ) : i(i) + { } + Foo( int i, int ) : i(i) + { } + Foo( const char*, int i, int ) : i(i) + { } +}; + +inline bool operator<( Foo l, Foo r ) +{ + return l.i < r.i; +} + +template< class PtrCont > +void check_ptr_list_of_impl() +{ + using namespace std; + using namespace boost; + using namespace boost::assign; + + PtrCont deq; + deq = ptr_list_of<Foo>( 42 )()()( 3, 3 )( "foo", 2, 1 ); + BOOST_CHECK( deq.size() == 5 ); + +} + +void check_ptr_list_of() +{ + check_ptr_list_of_impl< boost::ptr_deque<Foo> >(); + check_ptr_list_of_impl< boost::ptr_list<Foo> >(); + check_ptr_list_of_impl< boost::ptr_vector<Foo> >(); +} + + +#include <boost/test/unit_test.hpp> +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); + + test->add( BOOST_TEST_CASE( &check_ptr_list_of ) ); + + return test; +} + + diff --git a/src/boost/libs/assign/test/ptr_map_inserter.cpp b/src/boost/libs/assign/test/ptr_map_inserter.cpp new file mode 100644 index 000000000..4248ebd30 --- /dev/null +++ b/src/boost/libs/assign/test/ptr_map_inserter.cpp @@ -0,0 +1,99 @@ +// Boost.Assign library +// +// Copyright Thorsten Ottosen 2003-2004. Use, modification and +// distribution is subject to 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) +// +// For more information, see http://www.boost.org/libs/assign/ +// + +#include <boost/detail/workaround.hpp> + +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +# pragma warn -8091 // suppress warning in Boost.Test +# pragma warn -8057 // unused argument argc/argv in Boost.Test +#endif + + +#include <boost/assign/ptr_map_inserter.hpp> +#include <boost/test/test_tools.hpp> +#include <boost/ptr_container/ptr_map.hpp> +#include <typeinfo> +#include <string> + +// +// abstract base class definition +// +struct abstract_base +{ + virtual ~abstract_base() {} + virtual void foo() = 0; + virtual abstract_base* clone() const = 0; +}; + +struct implementation : abstract_base +{ + implementation() + { } + + implementation( const implementation& ) + { } + + implementation( int ) + { } + + implementation( int, int ) + { } + + implementation( int, std::string, int, std::string ) + { } + + virtual void foo() {} + virtual abstract_base* clone() const + { + return new implementation( *this ); + } +}; + + +void check_ptr_map_inserter() +{ + +#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING + + boost::ptr_map<std::string, abstract_base> m; + boost::assign::ptr_map_insert<implementation>( m ) + ( "foo", 1, "two", 3, "four" ) + ( "bar", 41, "42", 43, "44" ); + BOOST_CHECK_EQUAL( m.size(), 2u ); + BOOST_CHECK( typeid(m.at("foo")) == typeid(implementation) ); + +#endif + + boost::ptr_map<std::string,implementation> m2; + boost::assign::ptr_map_insert( m2 ) + ( "foobar", 1, "two", 3, "four" ) + ( "key1" )( "key2" )( "key3" )( "key4" ) + ( "key5", 42 )( "key6", 42, 42 ); + + BOOST_CHECK_EQUAL( m2.size(), 7u ); + boost::assign::ptr_map_insert( m2 )( "key1" ); + BOOST_CHECK_EQUAL( m2.size(), 7u ); // duplicates not inserted + +} + + + +#include <boost/test/unit_test.hpp> +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); + + test->add( BOOST_TEST_CASE( &check_ptr_map_inserter ) ); + + return test; +} + diff --git a/src/boost/libs/assign/test/static_list_of.cpp b/src/boost/libs/assign/test/static_list_of.cpp new file mode 100644 index 000000000..b28cc24f6 --- /dev/null +++ b/src/boost/libs/assign/test/static_list_of.cpp @@ -0,0 +1,98 @@ +// Boost.Assign library +// +// Copyright Thorsten Ottosen 2003-2004. Use, modification and +// distribution is subject to 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) +// +// For more information, see http://www.boost.org/libs/assign/ +// + + +#include <boost/detail/workaround.hpp> + +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +# pragma warn -8091 // suppress warning in Boost.Test +# pragma warn -8057 // unused argument argc/argv in Boost.Test +#endif + +#include <boost/assign/list_of.hpp> +#include <boost/array.hpp> +#include <boost/test/test_tools.hpp> +#include <algorithm> +#include <iostream> + +template< class Range > +void print( const Range& r ) +{ + std::cout << "\n printing " << typeid(r).name() << " \n"; + std::cout << "\n"; + for( typename Range::iterator i = r.begin(), e = r.end(); + i !=e; ++i ) + std::cout << " " << *i; +} + +template< class Range > +void sort( const Range& r ) +{ + std::cout << "\n sorting " << typeid(r).name() << " \n"; + std::sort( r.begin(), r.end() ); + print( r ); +} + +template< class Range, class Pred > +void sort( const Range& r, Pred pred ) +{ + std::cout << "\n sorting " << typeid(r).name() << " \n"; + std::sort( r.begin(), r.end(), pred ); + print( r ); +} + +template< class Range > +typename Range::const_iterator max_element( const Range& r ) +{ + return std::max_element( r.begin(), r.end() ); +} + + + +void check_static_list_of() +{ + using namespace boost::assign; + + BOOST_CHECK( cref_list_of<5>( 1 )( 2 )( 3 )( 4 ).size() == 4 ); + + int a=1,b=5,c=3,d=4,e=2,f=9,g=0,h=7; + + int& max = *max_element( ref_list_of<8>(a)(b)(c)(d)(e)(f)(g)(h) ); + BOOST_CHECK_EQUAL( max, f ); + max = 8; + BOOST_CHECK_EQUAL( f, 8 ); + const int& const_max = *max_element( cref_list_of<8>(a)(b)(c)(d)(e)(f)(g)(h) ); + BOOST_CHECK_EQUAL( max, const_max ); + + print( ref_list_of<8>(a)(b)(c)(d)(e)(f)(g)(h) ); + print( cref_list_of<8>(a)(b)(c)(d)(e)(f)(g)(h) ); + + boost::array<int,4> array = cref_list_of<4>(1)(2)(3)(4); + + BOOST_CHECK_EQUAL( array[0], 1 ); + BOOST_CHECK_EQUAL( array[3], 4 ); + // + //print( cref_list_of<5>( "foo" )( "bar" )( "foobar" ) ); + // +} + +#include <boost/test/unit_test.hpp> +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); + + test->add( BOOST_TEST_CASE( &check_static_list_of ) ); + + return test; +} + + diff --git a/src/boost/libs/assign/test/std.cpp b/src/boost/libs/assign/test/std.cpp new file mode 100644 index 000000000..bb2d8fbe5 --- /dev/null +++ b/src/boost/libs/assign/test/std.cpp @@ -0,0 +1,231 @@ +// Boost.Assign library +// +// Copyright Thorsten Ottosen 2003-2004. Use, modification and +// distribution is subject to 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) +// +// For more information, see http://www.boost.org/libs/assign/ +// + + +#include <boost/detail/workaround.hpp> + +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +# pragma warn -8091 // suppress warning in Boost.Test +# pragma warn -8057 // unused argument argc/argv in Boost.Test +#endif + +#include <boost/assign/std.hpp> +#include <boost/test/test_tools.hpp> +#include <utility> +#include <string> + +using std::deque; +using std::list; +using std::vector; +using std::set; +using std::multiset; +using std::map; +using std::multimap; +using std::stack; +using std::queue; +using std::priority_queue; +using std::string; +using std::pair; +using std::make_pair; +using namespace boost::assign; + +template< typename K, typename V > +inline pair<K,V> P( K k, V v ) +{ + return make_pair( k, v ); +} + +struct three +{ + three( int, int, int ) { } + three( const string&, const string&, const string& ) { } +}; + +struct four +{ + four( int, int, int, int ) { } + four( const string&, const string&, const string&, const string& ) { } +}; + +struct five +{ + five( int, int, int, int, int ) { } + five( const string&, const string&, const string&, + const string&, const string& ) { } +}; + + + +template< class C > +void test_int_sequence() +{ + C c; + + BOOST_CHECK_EQUAL( c.size(), 0u ); + c +=1,2,3,4,5,6,7,8,9,10; + BOOST_CHECK_EQUAL( c.size(), 10u ); +} + + + +template< class C > +void test_string_sequence() +{ + C c; + + BOOST_CHECK_EQUAL( c.size(), 0u ); + c += "1","2","3","4","5","6","7","8","9","10"; + BOOST_CHECK_EQUAL( c.size(), 10u ); +} + + + +typedef pair<string,int> two_tuple; + +template< class C > +void test_tuple_sequence() +{ + C c; + + BOOST_CHECK_EQUAL( c.size(), 0u ); + c += P("1",1), P("2",2), P("3",3), P("4",4), P("5",5), P("6",6), + P("7",7), P("8",8), P("9",9), P("10",10); + BOOST_CHECK_EQUAL( c.size(), 10u ); +} + + + +template< class M > +void test_map() +{ + M m; + m += P( "january", 31 ), P( "february", 28 ), + P( "march", 31 ), P( "april", 30 ), + P( "may", 31 ), P( "june", 30 ), + P( "july", 31 ), P( "august", 31 ), + P( "september", 30 ), P( "october", 31 ), + P( "november", 30 ), P( "december", 31 ); + BOOST_CHECK_EQUAL( m.size(), 12u ); + m.clear(); + insert( m ) + ( "january", 31 )( "february", 28 ) + ( "march", 31 )( "april", 30 ) + ( "may", 31 )( "june", 30 ) + ( "july", 31 )( "august", 31 ) + ( "september", 30 )( "october", 31 ) + ( "november", 30 )( "december", 31 ); + BOOST_CHECK_EQUAL( m.size(), 12u ); +} + + + +void test_tuple() +{ + vector<three> v_three; + vector<four> v_four; + vector<five> v_five; + + push_back( v_three ) (1,2,3) ("1","2","3"); + push_back( v_four ) (1,2,3,4) ("1","2","3","4"); + push_back( v_five ) (1,2,3,4,5) ("1","2","3","4","5"); + BOOST_CHECK_EQUAL( v_three.size(), 2u ); + BOOST_CHECK_EQUAL( v_four.size(), 2u ); + BOOST_CHECK_EQUAL( v_five.size(), 2u ); + +} + + + +void check_std() +{ + test_int_sequence< deque<int> >(); + test_int_sequence< list<int> >(); + test_int_sequence< vector<int> >(); + test_int_sequence< set<int> >(); + test_int_sequence< multiset<int> >(); + test_int_sequence< stack<int> >(); + test_int_sequence< queue<int> >(); + test_int_sequence< priority_queue<int> >(); + + test_string_sequence< deque<string> >(); + test_string_sequence< list<string> >(); + test_string_sequence< vector<string> >(); + test_string_sequence< set<string> >(); + test_string_sequence< multiset<string> >(); + test_string_sequence< stack<string> >(); + test_string_sequence< queue<string> >(); + test_string_sequence< priority_queue<string> >(); + + test_tuple_sequence< deque<two_tuple> >(); + test_tuple_sequence< list<two_tuple> >(); + test_tuple_sequence< vector<two_tuple> >(); + test_tuple_sequence< set<two_tuple> >(); + test_tuple_sequence< multiset<two_tuple> >(); + test_tuple_sequence< stack<two_tuple> >(); + test_tuple_sequence< queue<two_tuple> >(); + test_tuple_sequence< priority_queue<two_tuple> >(); + test_tuple(); + + deque<int> di; + push_back( di )( 1 ); + push_front( di )( 2 ); + BOOST_CHECK_EQUAL( di[0], 2 ); + BOOST_CHECK_EQUAL( di[1], 1 ); + + list<int> li; + push_back( li )( 2 ); + push_front( li )( 1 ); + BOOST_CHECK_EQUAL( li.front(), 1 ); + BOOST_CHECK_EQUAL( li.back(), 2 ); + + vector<int> vi; + push_back( vi ) = 2,3; + BOOST_CHECK_EQUAL( vi[0], 2 ); + BOOST_CHECK_EQUAL( vi[1], 3 ); + + set<int> si; + insert( si )( 4 ); + BOOST_CHECK_EQUAL( *si.find( 4 ), 4 ); + + multiset<int> msi; + insert( msi )( 5 ); + BOOST_CHECK_EQUAL( *msi.find( 5 ), 5 ); + + stack<int> sti; + push( sti )( 6 ); + BOOST_CHECK_EQUAL( sti.top(), 6 ); + + queue<int> qi; + push( qi )( 7 ); + BOOST_CHECK_EQUAL( qi.back(), 7 ); + + priority_queue<int> pqi; + push( pqi )( 8 ); + BOOST_CHECK_EQUAL( pqi.top(), 8 ); + + test_map< map<string,int> >(); + test_map< multimap<string,int> >(); + +} + + + +#include <boost/test/unit_test.hpp> +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); + + test->add( BOOST_TEST_CASE( &check_std ) ); + + return test; +} + diff --git a/src/boost/libs/assign/test/tuple_list_of.cpp b/src/boost/libs/assign/test/tuple_list_of.cpp new file mode 100644 index 000000000..807dd60ed --- /dev/null +++ b/src/boost/libs/assign/test/tuple_list_of.cpp @@ -0,0 +1,54 @@ +// Boost.Assign library +// +// Copyright Thorsten Ottosen 2003-2004. Use, modification and +// distribution is subject to 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) +// +// For more information, see http://www.boost.org/libs/assign/ +// + + +#include <boost/detail/workaround.hpp> + +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +# pragma warn -8091 // suppress warning in Boost.Test +# pragma warn -8057 // unused argument argc/argv in Boost.Test +#endif + +#include <boost/assign/list_of.hpp> +#include <boost/test/test_tools.hpp> +#include <algorithm> +#include <iostream> +#include <string> +#include <vector> +#include <map> + +void check_tuple_list_of() +{ + using namespace boost::assign; + + typedef boost::tuple<int,std::string,int> tuple; + + std::vector<tuple> v = tuple_list_of( 1, "foo", 2 )( 3, "bar", 4 ); + BOOST_CHECK( v.size() == 2 ); + BOOST_CHECK( boost::get<0>( v[1] ) == 3 ); + + std::map<std::string,int> m = pair_list_of( "foo", 3 )( "bar", 5 ); + BOOST_CHECK( m.size() == 2 ); + BOOST_CHECK( m["foo"] == 3 ); +} + +#include <boost/test/unit_test.hpp> +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); + + test->add( BOOST_TEST_CASE( &check_tuple_list_of ) ); + + return test; +} + + |