source: trunk/nv/stl/unordered_map.hh @ 401

Last change on this file since 401 was 401, checked in by epyon, 10 years ago
  • clang/gcc fixes
  • removed aligned array, usage of alignas should work now
File size: 3.1 KB
RevLine 
[390]1// Copyright (C) 2015 ChaosForge Ltd
2// http://chaosforge.org/
3//
[395]4// This file is part of Nova libraries.
5// For conditions of distribution and use, see copying.txt file in root folder.
[390]6
7/**
[395]8 * @file unordered_map.hh
9 * @author Kornel Kisielewicz epyon@chaosforge.org
10 * @brief unordered_map
11 */
[390]12
13#ifndef NV_STL_UNORDERED_MAP_HH
14#define NV_STL_UNORDERED_MAP_HH
15
[395]16#include <nv/common.hh>
[390]17#include <nv/stl/container/hash_table.hh>
18#include <nv/stl/utility/pair.hh>
19
20namespace nv
21{
22        template < typename Pair >
23        struct use_first
24        {
25                typedef Pair                      argument_type;
26                typedef typename Pair::first_type result_type;
27                const result_type& operator()( const Pair& arg ) const
28                {
29                        return arg.first;
30                }
31        };
32       
33        template <
34                typename Key,
35                typename T,
36                typename Hash = hash< Key >,
37                typename KeyEqual = equal_to< Key >
38//              typename Hash = hash<Key>(),
39//              typename Predicate = equal_to<Key>,
40        >
41        class unordered_map
42                : public hash_table< hash_table_entry_stl_map< Key, T, size_t, KeyEqual, Hash > >
43        {
44        public:
45                typedef hash_table< hash_table_entry_stl_map< Key, T, size_t, KeyEqual, Hash > > base_type;
46                typedef unordered_map< Key, T, Hash, KeyEqual >                                  this_type;
[401]47                typedef typename base_type::value_type                                           value_type;
48                typedef typename base_type::pointer                                              pointer;
49                typedef typename base_type::const_pointer                                        const_pointer;
50                typedef typename base_type::reference                                            reference;
51                typedef typename base_type::const_reference                                      const_reference;
52                typedef typename base_type::iterator                                             iterator;
53                typedef typename base_type::const_iterator                                       const_iterator;
[390]54                typedef typename base_type::size_type                                            size_type;
[401]55                typedef typename base_type::difference_type                                      difference_type;
[390]56                typedef typename base_type::key_type                                             key_type;
57                typedef typename base_type::mapped_type                                          mapped_type;
58                typedef typename base_type::node_type                                            node_type;
59                typedef typename base_type::insert_return_type                                   insert_return_type;
60                typedef Hash                                                                     hasher;
61                typedef KeyEqual                                                                 key_equal;
62
63                unordered_map() : base_type() { }
64                explicit unordered_map( size_type bucket_count ) : base_type( bucket_count ) { }
65
66                mapped_type& operator[]( const key_type& key )
67                {
68                        return ( *base_type::insert_key( key ).first ).second;
69                }
70
71                using base_type::insert;
72       
73                // STL compatibility only, hint unused
74                iterator insert( const_iterator, const value_type& value )
75                {
76                        return base_type::insert( value ).first;
77                }
78
79        };
80
81}
82
83#endif // NV_STL_UNORDERED_MAP_HH
84
Note: See TracBrowser for help on using the repository browser.