From 75d03492c0a42031a987969a6eb20dd2121f54d1 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 13 Mar 2015 14:39:46 +0200 Subject: Rename set_key to map_key; feels more correct --- build/key-set | 59 ----------------------------------------------------------- build/map-key | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ build/target | 2 +- build/utility | 4 ++-- 4 files changed, 62 insertions(+), 62 deletions(-) delete mode 100644 build/key-set create mode 100644 build/map-key (limited to 'build') diff --git a/build/key-set b/build/key-set deleted file mode 100644 index 1d0b532..0000000 --- a/build/key-set +++ /dev/null @@ -1,59 +0,0 @@ -// file : build/key-set -*- C++ -*- -// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC -// license : MIT; see accompanying LICENSE file - -#ifndef BUILD_KEY_SET -#define BUILD_KEY_SET - -#include // declval() -#include // hash - -namespace build -{ - // Google the "Emulating Boost.MultiIndex with Standard Containers" blog - // post for deatils. - // - - template - struct set_key - { - mutable const T* p; - - set_key (const T* v = 0): p (v) {} - bool operator< (const set_key& x) const {return *p < *x.p;} - bool operator== (const set_key& x) const {return *p == *x.p;} - }; - - template - struct map_iterator_adapter: I - { - typedef const typename I::value_type::second_type value_type; - typedef value_type* pointer; - typedef value_type& reference; - - map_iterator_adapter () {} - map_iterator_adapter (I i): I (i) {} - - map_iterator_adapter& - operator= (I i) {static_cast (*this) = i; return *this;} - - reference operator* () const {return I::operator* ().second;} - pointer operator-> () const {return &I::operator-> ()->second;} - }; -} - -namespace std -{ - template - struct hash>: hash - { - size_t - operator() (build::set_key x) const - noexcept (noexcept (declval> () (*x.p))) - { - return hash::operator() (*x.p); - } - }; -} - -#endif // BUILD_KEY_SET diff --git a/build/map-key b/build/map-key new file mode 100644 index 0000000..43cdefe --- /dev/null +++ b/build/map-key @@ -0,0 +1,59 @@ +// file : build/map-key -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#ifndef BUILD_MAP_KEY +#define BUILD_MAP_KEY + +#include // declval() +#include // hash + +namespace build +{ + // Google the "Emulating Boost.MultiIndex with Standard Containers" blog + // post for deatils. + // + + template + struct map_key + { + mutable const T* p; + + map_key (const T* v = 0): p (v) {} + bool operator< (const map_key& x) const {return *p < *x.p;} + bool operator== (const map_key& x) const {return *p == *x.p;} + }; + + template + struct map_iterator_adapter: I + { + typedef const typename I::value_type::second_type value_type; + typedef value_type* pointer; + typedef value_type& reference; + + map_iterator_adapter () {} + map_iterator_adapter (I i): I (i) {} + + map_iterator_adapter& + operator= (I i) {static_cast (*this) = i; return *this;} + + reference operator* () const {return I::operator* ().second;} + pointer operator-> () const {return &I::operator-> ()->second;} + }; +} + +namespace std +{ + template + struct hash>: hash + { + size_t + operator() (build::map_key x) const + noexcept (noexcept (declval> () (*x.p))) + { + return hash::operator() (*x.p); + } + }; +} + +#endif // BUILD_MAP_KEY diff --git a/build/target b/build/target index 4405104..c961315 100644 --- a/build/target +++ b/build/target @@ -17,7 +17,7 @@ #include // move() #include -#include +#include // map_iterator_adapter #include #include #include diff --git a/build/utility b/build/utility index cd0d8ad..489a5eb 100644 --- a/build/utility +++ b/build/utility @@ -16,7 +16,7 @@ #include #include -#include +#include #include namespace build @@ -211,7 +211,7 @@ namespace build size () const {return static_cast (vec_.size ());} private: - using key_type = set_key; + using key_type = map_key; using value_type = string_table_element; using map_type = std::unordered_map; using traits = string_table_traits; -- cgit v1.1