| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- //
- // remap.hpp
- // remap
- //
- // Created by Sam Jaffe on 9/16/18.
- //
- #pragma once
- #include <map>
- #include <unordered_map>
- /*
- * A remap referres to a "value re-mapping object". This is used to allow us to
- * rename
- */
- template <typename T, typename Impl> class remap_base {
- public:
- using value_type = typename Impl::value_type;
- using key_type = typename Impl::key_type;
- using mapped_type = typename Impl::mapped_type;
- private:
- Impl impl_;
- public:
- remap_base(std::initializer_list<value_type> mappings) : impl_(mappings) {}
- mapped_type const & operator[](T const & value) const {
- auto it = impl_.find(value);
- return (it != impl_.end()) ? it->second : value;
- }
- };
- template <typename T, typename Compare = std::less<T>,
- typename Alloc = std::allocator<std::pair<T const, T>>>
- using remap = remap_base<T, std::map<T, T, Compare, Alloc>>;
- template <typename T, typename Hash = std::hash<T>,
- typename Equal = std::equal_to<T>,
- typename Alloc = std::allocator<std::pair<T const, T>>>
- using unordered_remap =
- remap_base<T, std::unordered_map<T, T, Hash, Equal, Alloc>>;
|