/* * test.cpp * * Created on: 08.10.2016 * Author: mike */ #include #include #include #include #include #include #include namespace hessian { struct hash; using null_t = boost::blank; using bool_t = bool; using int_t = std::int32_t; using long_t = std::int64_t; using double_t = double; using date_t = boost::posix_time::ptime; using string_t = std::string; using binary_t = std::basic_string; template using basic_list_t = std::vector; template using basic_map_t = std::unordered_map; template using basic_object_t = std::unordered_map; using value_t = boost::make_recursive_variant < null_t, bool_t, int_t, long_t, double_t, date_t, string_t, binary_t, basic_list_t, basic_map_t, basic_object_t >::type; using list_t = basic_list_t; using map_t = basic_map_t; using object_t = basic_object_t; struct hash { size_t operator()(const value_t& value) const noexcept; }; } #include namespace boost { size_t hash_value(const hessian::null_t& value) noexcept; size_t hash_value(const hessian::date_t& value) noexcept; size_t hash_value(const hessian::map_t& value) noexcept; size_t hash_value(const hessian::object_t& value) noexcept; } #include namespace boost { inline size_t hash_value(const hessian::null_t& value) noexcept { return 0xAAAAAAAAAAAAAAAA; } inline size_t hash_value(const hessian::date_t& value) noexcept { size_t seed = 0; hash_combine(seed, value.date().day_count().as_number()); hash_combine(seed, value.time_of_day().total_milliseconds()); return seed; } inline size_t hash_value(const hessian::map_t& value) noexcept { return hash_range(value.begin(), value.end()); } inline size_t hash_value(const hessian::object_t& value) noexcept { return hash_range(value.begin(), value.end()); } } namespace hessian { inline size_t hash::operator()(const value_t& value) const noexcept { return boost::hash_value(value); } } int main() { using namespace hessian; using namespace std::string_literals; value_t value; value = null_t(); value = map_t { {int_t(1), bool_t(true)}, {long_t(2), double_t(3.14)} }; value = object_t { {"foo"s, bool_t(true)}, {"bar"s, double_t(3.14)} }; return 0; }