summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/type_erasure/test/test_increment.cpp
blob: f864dfaf363f9fafeba10d08b36b805001fa983c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Boost.TypeErasure library
//
// Copyright 2011 Steven Watanabe
//
// 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)
//
// $Id$

#include <boost/type_erasure/any.hpp>
#include <boost/type_erasure/tuple.hpp>
#include <boost/type_erasure/builtin.hpp>
#include <boost/type_erasure/operators.hpp>
#include <boost/type_erasure/any_cast.hpp>
#include <boost/mpl/vector.hpp>

#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>

using namespace boost::type_erasure;

template<class T = _self>
struct common : ::boost::mpl::vector<
    destructible<T>,
    copy_constructible<T>,
    typeid_<T>
> {};

BOOST_AUTO_TEST_CASE(test_value)
{
    typedef ::boost::mpl::vector<common<>, incrementable<> > test_concept;
    any<test_concept> x(1);
    ++x;
    BOOST_CHECK_EQUAL(any_cast<int>(x), 2);
    any<test_concept> y(x++);
    BOOST_CHECK_EQUAL(any_cast<int>(x), 3);
    BOOST_CHECK_EQUAL(any_cast<int>(y), 2);
}

BOOST_AUTO_TEST_CASE(test_reference)
{
    typedef ::boost::mpl::vector<common<>, incrementable<> > test_concept;
    int i = 1;
    any<test_concept, _self&> x(i);
    ++x;
    BOOST_CHECK_EQUAL(i, 2);
    any<test_concept> y(x++);
    BOOST_CHECK_EQUAL(i, 3);
    BOOST_CHECK_EQUAL(any_cast<int>(y), 2);
}