PageRenderTime 13ms CodeModel.GetById 1ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/unordered/test/unordered/incomplete_test.cpp

http://hadesmem.googlecode.com/
C++ | 147 lines | 95 code | 33 blank | 19 comment | 0 complexity | 7dc6635a4fd0f57f9c848f91aef9742c MD5 | raw file
  1
  2// Copyright 2009 Daniel James.
  3// Distributed under the Boost Software License, Version 1.0. (See accompanying
  4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5
  6#include "../helpers/prefix.hpp"
  7
  8#include <boost/unordered_map.hpp>
  9#include <boost/unordered_set.hpp>
 10
 11namespace x
 12{
 13    struct D { boost::unordered_map<D, D> x; };
 14}
 15
 16namespace test
 17{
 18    // Declare, but don't define some types.
 19
 20    struct value;
 21    struct hash;
 22    struct equals;
 23    template <class T>
 24    struct malloc_allocator;
 25
 26    // Declare some instances
 27    
 28    typedef boost::unordered_map<value, value, hash, equals,
 29        malloc_allocator<std::pair<value const, value> > > map;
 30    typedef boost::unordered_multimap<value, value, hash, equals,
 31        malloc_allocator<std::pair<value const, value> > > multimap;
 32    typedef boost::unordered_set<value, hash, equals,
 33        malloc_allocator<value> > set;
 34    typedef boost::unordered_multiset<value, hash, equals,
 35        malloc_allocator<value> > multiset;
 36    
 37    // Now define the types which are stored as members, as they are needed for
 38    // declaring struct members.
 39
 40    struct hash { 
 41        template <typename T>
 42        std::size_t operator()(T const&) const { return 0; }
 43    };
 44
 45    struct equals {
 46        template <typename T>
 47        bool operator()(T const&, T const&) const { return true; }
 48    };
 49
 50}
 51
 52#include "../helpers/allocator.hpp"
 53
 54namespace test
 55{
 56    // Declare some members of a structs.
 57    //
 58    // Incomplete hash, equals and allocator aren't here supported at the
 59    // moment.
 60    
 61    struct struct1 {
 62        boost::unordered_map<struct1, struct1, hash, equals,
 63            malloc_allocator<std::pair<struct1 const, struct1> > > x;
 64    };
 65    struct struct2 {
 66        boost::unordered_multimap<struct2, struct2, hash, equals,
 67            malloc_allocator<std::pair<struct2 const, struct2> > > x;
 68    };
 69    struct struct3 {
 70        boost::unordered_set<struct3, hash, equals,
 71            malloc_allocator<struct3> > x;
 72    };
 73    struct struct4 {
 74        boost::unordered_multiset<struct4, hash, equals,
 75            malloc_allocator<struct4> > x;
 76    };
 77    
 78    // Now define the value type.
 79
 80    struct value {};
 81
 82    // Create some instances.
 83    
 84    test::map m1;
 85    test::multimap m2;
 86    test::set s1;
 87    test::multiset s2;
 88
 89    test::struct1 c1;
 90    test::struct2 c2;
 91    test::struct3 c3;
 92    test::struct4 c4;
 93
 94    // Now declare, but don't define, the operators required for comparing
 95    // elements.
 96
 97    std::size_t hash_value(value const&);
 98    bool operator==(value const&, value const&);
 99
100    std::size_t hash_value(struct1 const&);
101    std::size_t hash_value(struct2 const&);
102    std::size_t hash_value(struct3 const&);
103    std::size_t hash_value(struct4 const&);
104    
105    bool operator==(struct1 const&, struct1 const&);
106    bool operator==(struct2 const&, struct2 const&);
107    bool operator==(struct3 const&, struct3 const&);
108    bool operator==(struct4 const&, struct4 const&);
109    
110    // And finally use these
111    
112    void use_types()
113    {
114        test::value x;
115        m1[x] = x;
116        m2.insert(std::make_pair(x, x));
117        s1.insert(x);
118        s2.insert(x);
119
120        c1.x.insert(std::make_pair(c1, c1));
121        c2.x.insert(std::make_pair(c2, c2));
122        c3.x.insert(c3);
123        c4.x.insert(c4);
124    }
125
126    // And finally define the operators required for comparing elements.
127
128    std::size_t hash_value(value const&) { return 0; }
129    bool operator==(value const&, value const&) { return true; }
130
131    std::size_t hash_value(struct1 const&) { return 0; }
132    std::size_t hash_value(struct2 const&) { return 0; }
133    std::size_t hash_value(struct3 const&) { return 0; }
134    std::size_t hash_value(struct4 const&) { return 0; }
135    
136    bool operator==(struct1 const&, struct1 const&) { return true; }
137    bool operator==(struct2 const&, struct2 const&) { return true; }
138    bool operator==(struct3 const&, struct3 const&) { return true; }
139    bool operator==(struct4 const&, struct4 const&) { return true; }
140}
141
142int main() {
143    // This could just be a compile test, but I like to be able to run these
144    // things. It's probably irrational, but I find it reassuring.
145
146    test::use_types();
147}