File: test_tagged.cpp

package info (click to toggle)
boost1.74 1.74.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 464,084 kB
  • sloc: cpp: 3,338,324; xml: 131,293; python: 33,088; ansic: 14,336; asm: 4,034; sh: 3,351; makefile: 1,193; perl: 1,036; yacc: 478; php: 212; ruby: 102; lisp: 24; sql: 13; csh: 6
file content (107 lines) | stat: -rw-r--r-- 3,270 bytes parent folder | download | duplicates (8)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Boost.Bimap
//
// Copyright (c) 2006-2007 Matias Capeletto
//
// 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)

//  VC++ 8.0 warns on usage of certain Standard Library and API functions that
//  can be cause buffer overruns or other possible security issues if misused.
//  See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx
//  But the wording of the warning is misleading and unsettling, there are no
//  portable alternative functions, and VC++ 8.0's own libraries use the
//  functions in question. So turn off the warnings.
#define _CRT_SECURE_NO_DEPRECATE
#define _SCL_SECURE_NO_DEPRECATE

#include <boost/config.hpp>

#include <boost/core/lightweight_test.hpp>

#include <boost/static_assert.hpp>

// Boost.MPL
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/type_traits/add_const.hpp>

// Boost.Bimap
#include <boost/bimap/detail/test/check_metadata.hpp>

// Boost.Bimap.Tags
#include <boost/bimap/tags/tagged.hpp>
#include <boost/bimap/tags/support/default_tagged.hpp>
#include <boost/bimap/tags/support/is_tagged.hpp>
#include <boost/bimap/tags/support/overwrite_tagged.hpp>
#include <boost/bimap/tags/support/tag_of.hpp>
#include <boost/bimap/tags/support/value_type_of.hpp>
#include <boost/bimap/tags/support/apply_to_value_type.hpp>




BOOST_BIMAP_TEST_STATIC_FUNCTION( test_metafunctions )
{
    using namespace boost::bimaps::tags::support;
    using namespace boost::bimaps::tags;
    using namespace boost::mpl::placeholders;
    using namespace boost;

    struct tag      {};
    struct value    {};

    // Test apply_to_value_type metafunction
    // tagged<value,tag> ----(add_const<_>)----> tagged<value const,tag>
    typedef tagged< value, tag > ttype;
    typedef apply_to_value_type< add_const<_>,ttype>::type result;
    typedef is_same<tagged<value const,tag>,result> compare;
    BOOST_MPL_ASSERT_MSG(compare::value,tag,(result));
}

struct tag_a {};
struct tag_b {};
struct data  {};

void test_function()
{

    using namespace boost::bimaps::tags::support;
    using namespace boost::bimaps::tags;
    using boost::is_same;

    typedef tagged< data, tag_a > data_a;
    typedef tagged< data, tag_b > data_b;

    BOOST_TEST(( is_same< data_a::value_type   , data  >::value ));
    BOOST_TEST(( is_same< data_a::tag          , tag_a >::value ));

    BOOST_TEST((
        is_same< overwrite_tagged < data_a, tag_b >::type, data_b >::value
    ));
    BOOST_TEST((
        is_same< default_tagged   < data_a, tag_b >::type, data_a >::value
    ));
    BOOST_TEST((
        is_same< default_tagged   < data  , tag_b >::type, data_b >::value
    ));

    BOOST_TEST(( is_tagged< data   >::value == false ));
    BOOST_TEST(( is_tagged< data_a >::value == true  ));

    BOOST_TEST(( is_same< value_type_of<data_a>::type, data  >::value ));
    BOOST_TEST(( is_same< tag_of       <data_a>::type, tag_a >::value ));

}

int main()
{
    test_function();

    // Test metanfunctions
    BOOST_BIMAP_CALL_TEST_STATIC_FUNCTION( test_metafunctions );

    return boost::report_errors();
}