From f8f44f0a8bae0667c6f5ff2315b220144785c6fb Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 29 Feb 2012 17:08:36 +0200 Subject: Support for C++11 containers (array, forward_list, unordered) --- common/container/test.hxx | 95 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 2 deletions(-) (limited to 'common/container/test.hxx') diff --git a/common/container/test.hxx b/common/container/test.hxx index 31e9542..ff2a4e2 100644 --- a/common/container/test.hxx +++ b/common/container/test.hxx @@ -5,12 +5,21 @@ #ifndef TEST_HXX #define TEST_HXX +#include // HAVE_CXX11 + #include #include #include #include #include +#ifdef HAVE_CXX11 +# include +# include +# include +# include +#endif + #include #pragma db value @@ -31,6 +40,12 @@ operator== (const comp& x, const comp& y) } inline bool +operator!= (const comp& x, const comp& y) +{ + return !(x == y); +} + +inline bool operator< (const comp& x, const comp& y) { return x.num != y.num ? x.num < y.num : x.str < y.str; @@ -43,10 +58,40 @@ typedef std::vector str_vector; typedef std::set num_set; typedef std::set str_set; +typedef std::set comp_set; typedef std::map num_str_map; typedef std::map str_num_map; typedef std::map num_comp_map; +typedef std::map comp_str_map; + +#ifdef HAVE_CXX11 +struct comp_hash +{ + std::size_t + operator() (comp const& x) const {return nh (x.num) + sh (x.str);} + + std::hash nh; + std::hash sh; +}; + +typedef std::array num_array; +typedef std::array str_array; +typedef std::array comp_array; + +typedef std::forward_list num_flist; +typedef std::forward_list str_flist; +typedef std::forward_list comp_flist; + +typedef std::unordered_set num_uset; +typedef std::unordered_set str_uset; +typedef std::unordered_set comp_uset; + +typedef std::unordered_map num_str_umap; +typedef std::unordered_map str_num_umap; +typedef std::unordered_map num_comp_umap; +typedef std::unordered_map comp_str_umap; +#endif #pragma db value struct cont_comp1 @@ -103,14 +148,41 @@ struct object // num_set ns; str_set ss; - std::set cs; + comp_set cs; // map // num_str_map nsm; str_num_map snm; num_comp_map ncm; - std::map csm; + comp_str_map csm; + +#ifdef HAVE_CXX11 + // array + // + num_array na; + str_array sa; + comp_array ca; + + // forward_list + // + num_flist nfl; + str_flist sfl; + comp_flist cfl; + + // unordered_set + // + num_uset nus; + str_uset sus; + comp_uset cus; + + // unordered_map + // + num_str_umap nsum; + str_num_umap snum; + num_comp_umap ncum; + comp_str_umap csum; +#endif std::string str; }; @@ -152,6 +224,25 @@ operator== (const object& x, const object& y) x.ncm == y.ncm && x.csm == y.csm && +#ifdef HAVE_CXX11 + x.na == y.na && + x.sa == y.sa && + x.ca == y.ca && + + x.nfl == y.nfl && + x.sfl == y.sfl && + x.cfl == y.cfl && + + x.nus == y.nus && + x.sus == y.sus && + x.cus == y.cus && + + x.nsum == y.nsum && + x.snum == y.snum && + x.ncum == y.ncum && + x.csum == y.csum && +#endif + x.str == y.str; } -- cgit v1.1