diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-02-29 17:08:36 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-02-29 17:08:36 +0200 |
commit | f8f44f0a8bae0667c6f5ff2315b220144785c6fb (patch) | |
tree | e8af9d6ff1ab9b8e54790bfda58521694eae4733 | |
parent | 528f932066ecfc6a9fb5477031114da5aeceeb9c (diff) |
Support for C++11 containers (array, forward_list, unordered)
-rw-r--r-- | common/container/driver.cxx | 206 | ||||
-rw-r--r-- | common/container/test.hxx | 95 |
2 files changed, 299 insertions, 2 deletions
diff --git a/common/container/driver.cxx b/common/container/driver.cxx index d19dca1..469bba2 100644 --- a/common/container/driver.cxx +++ b/common/container/driver.cxx @@ -38,6 +38,23 @@ main (int argc, char* argv[]) empty.num = 0; empty.str = ""; +#ifdef HAVE_CXX11 + // array + // + empty.na[0] = 123; + empty.na[1] = 234; + empty.na[2] = 345; + + empty.sa[0] = "aaa"; + empty.sa[1] = "bbbb"; + empty.sa[2] = "ccccc"; + + empty.ca[0] = comp (123, "aaa"); + empty.ca[1] = comp (234, "bbbb"); + empty.ca[2] = comp (345, "ccccc"); +#endif + + // // med // @@ -89,6 +106,58 @@ main (int argc, char* argv[]) med.csm[comp (123, "aaa")] = "aaa"; med.csm[comp (234, "bbbb")] = "bbbb"; +#ifdef HAVE_CXX11 + // array + // + med.na[0] = 123; + med.na[1] = 234; + med.na[2] = 345; + + med.sa[0] = "aaa"; + med.sa[1] = "bbbb"; + med.sa[2] = "ccccc"; + + med.ca[0] = comp (123, "aaa"); + med.ca[1] = comp (234, "bbbb"); + med.ca[2] = comp (345, "ccccc"); + + // forward_list + // + med.nfl.push_front (234); + med.nfl.push_front (123); + + med.sfl.push_front ("bbbb"); + med.sfl.push_front ("aaa"); + + med.cfl.push_front (comp (234, "bbbb")); + med.cfl.push_front (comp (123, "aaa")); + + // unordered_set + // + med.nus.insert (123); + med.nus.insert (234); + + med.sus.insert ("aaa"); + med.sus.insert ("bbbb"); + + med.cus.insert (comp (123, "aaa")); + med.cus.insert (comp (234, "bbbb")); + + // unordered_map + // + med.nsum[123] = "aaa"; + med.nsum[234] = "bbbb"; + + med.snum["aaa"] = 123; + med.snum["bbbb"] = 234; + + med.ncum[123] = comp (123, "aaa"); + med.ncum[234] = comp (234, "bbbb"); + + med.csum[comp (123, "aaa")] = "aaa"; + med.csum[comp (234, "bbbb")] = "bbbb"; +#endif + // // full // @@ -152,6 +221,68 @@ main (int argc, char* argv[]) full.csm[comp (2345, "bbbbb")] = "bbbbb"; full.csm[comp (3456, "cccccc")] = "cccccc"; +#ifdef HAVE_CXX11 + // array + // + full.na[0] = 123; + full.na[1] = 234; + full.na[2] = 345; + + full.sa[0] = "aaa"; + full.sa[1] = "bbbb"; + full.sa[2] = "ccccc"; + + full.ca[0] = comp (123, "aaa"); + full.ca[1] = comp (234, "bbbb"); + full.ca[2] = comp (345, "ccccc"); + + // forward_list + // + full.nfl.push_front (345); + full.nfl.push_front (234); + full.nfl.push_front (123); + + full.sfl.push_front ("ccccc"); + full.sfl.push_front ("bbbb"); + full.sfl.push_front ("aaa"); + + full.cfl.push_front (comp (345, "ccccc")); + full.cfl.push_front (comp (234, "bbbb")); + full.cfl.push_front (comp (123, "aaa")); + + // unordered_set + // + full.nus.insert (1234); + full.nus.insert (2345); + full.nus.insert (3456); + + full.sus.insert ("aaaa"); + full.sus.insert ("bbbbb"); + full.sus.insert ("cccccc"); + + full.cus.insert (comp (1234, "aaaa")); + full.cus.insert (comp (2345, "bbbbb")); + full.cus.insert (comp (3456, "cccccc")); + + // unordered_map + // + full.nsum[1234] = "aaaa"; + full.nsum[2345] = "bbbbb"; + full.nsum[3456] = "cccccc"; + + full.snum["aaaa"] = 1234; + full.snum["bbbbb"] = 2345; + full.snum["cccccc"] = 3456; + + full.ncum[1234] = comp (1234, "aaaa"); + full.ncum[2345] = comp (2345, "bbbbb"); + full.ncum[3456] = comp (3456, "cccccc"); + + full.csum[comp (1234, "aaaa")] = "aaaa"; + full.csum[comp (2345, "bbbbb")] = "bbbbb"; + full.csum[comp (3456, "cccccc")] = "cccccc"; +#endif + // persist // { @@ -182,19 +313,37 @@ main (int argc, char* argv[]) empty.num = 99; empty.str = "xx"; + empty.nv.push_back (12); empty.sv.push_back ("aa"); empty.cv.push_back (comp (12, "aa")); empty.uv.push_back (12); empty.sl.push_back ("aa"); + empty.ns.insert (12); empty.ss.insert ("aa"); empty.cs.insert (comp (12, "aa")); + empty.nsm[12] = "aa"; empty.snm["aa"] = 12; empty.ncm[12] = comp (12, "aa"); empty.csm[comp (12, "aa")] = "aa"; +#ifdef HAVE_CXX11 + empty.nfl.push_front (12); + empty.sfl.push_front ("aa"); + empty.cfl.push_front (comp (12, "aa")); + + empty.nus.insert (12); + empty.sus.insert ("aa"); + empty.cus.insert (comp (12, "aa")); + + empty.nsum[12] = "aa"; + empty.snum["aa"] = 12; + empty.ncum[12] = comp (12, "aa"); + empty.csum[comp (12, "aa")] = "aa"; +#endif + // // med // @@ -218,6 +367,21 @@ main (int argc, char* argv[]) med.ncm.clear (); med.csm.clear (); +#ifdef HAVE_CXX11 + med.nfl.clear (); + med.sfl.clear (); + med.cfl.clear (); + + med.nus.clear (); + med.sus.clear (); + med.cus.clear (); + + med.nsum.clear (); + med.snum.clear (); + med.ncum.clear (); + med.csum.clear (); +#endif + // // full // @@ -266,6 +430,48 @@ main (int argc, char* argv[]) full.csm[comp (3456, "cccccc")] += "c"; full.csm[comp (4567, "ddddddd")] = "ddddddd"; +#ifdef HAVE_CXX11 + // array + // + full.na[0]++; + full.sa[0] += 'a'; + full.ca[0].num++; + full.ca[0].str += 'a'; + + // forward_list + // + full.nfl.front ()++; + full.nfl.push_front (4567); + + full.sfl.front () += 'a'; + full.sfl.push_front ("ddddddd"); + + full.cfl.front ().num++; + full.cfl.front ().str += 'a'; + full.cfl.push_front (comp (4567, "ddddddd")); + + // unordered_set + // + full.nus.insert (4567); + full.sus.insert ("ddddddd"); + full.cus.insert (comp (4567, "ddddddd")); + + // unordered_map + // + full.nsum[3456] += 'c'; + full.nsum[4567] = "ddddddd"; + + full.snum["cccccc"]++; + full.snum["ddddddd"] = 4567; + + full.ncum[3456].num++; + full.ncum[3456].str += 'c'; + full.ncum[4567] = comp (4567, "ddddddd"); + + full.csum[comp (3456, "cccccc")] += "c"; + full.csum[comp (4567, "ddddddd")] = "ddddddd"; +#endif + // update // { 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 <common/config.hxx> // HAVE_CXX11 + #include <map> #include <set> #include <list> #include <vector> #include <string> +#ifdef HAVE_CXX11 +# include <array> +# include <forward_list> +# include <unordered_map> +# include <unordered_set> +#endif + #include <odb/core.hxx> #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<std::string> str_vector; typedef std::set<int> num_set; typedef std::set<std::string> str_set; +typedef std::set<comp> comp_set; typedef std::map<int, std::string> num_str_map; typedef std::map<std::string, int> str_num_map; typedef std::map<int, comp> num_comp_map; +typedef std::map<comp, std::string> 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<int> nh; + std::hash<std::string> sh; +}; + +typedef std::array<int, 3> num_array; +typedef std::array<std::string, 3> str_array; +typedef std::array<comp, 3> comp_array; + +typedef std::forward_list<int> num_flist; +typedef std::forward_list<std::string> str_flist; +typedef std::forward_list<comp> comp_flist; + +typedef std::unordered_set<int> num_uset; +typedef std::unordered_set<std::string> str_uset; +typedef std::unordered_set<comp, comp_hash> comp_uset; + +typedef std::unordered_map<int, std::string> num_str_umap; +typedef std::unordered_map<std::string, int> str_num_umap; +typedef std::unordered_map<int, comp> num_comp_umap; +typedef std::unordered_map<comp, std::string, comp_hash> comp_str_umap; +#endif #pragma db value struct cont_comp1 @@ -103,14 +148,41 @@ struct object // num_set ns; str_set ss; - std::set<comp> cs; + comp_set cs; // map // num_str_map nsm; str_num_map snm; num_comp_map ncm; - std::map<comp, std::string> 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; } |