From 5f821d47f0ee08a3a08962d0dc641326618dbf50 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 25 Apr 2011 12:30:05 +0200 Subject: Reuse container traits from composite values --- common/inheritance/driver.cxx | 4 ++++ common/inheritance/test.hxx | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'common/inheritance') diff --git a/common/inheritance/driver.cxx b/common/inheritance/driver.cxx index 203e912..99dc1c5 100644 --- a/common/inheritance/driver.cxx +++ b/common/inheritance/driver.cxx @@ -29,6 +29,7 @@ main (int argc, char* argv[]) auto_ptr db (create_database (argc, argv)); base b; + b.comp_.bools.push_back (true); b.comp_.num = 10; b.comp_.str = "comp bbb"; b.comp_.nums.push_back (101); @@ -39,6 +40,7 @@ main (int argc, char* argv[]) b.strs_.push_back ("bbb two"); object1 o1; + o1.comp_.bools.push_back (false); o1.comp_.num = 11; o1.comp_.str = "comp o1o1o1"; o1.comp_.nums.push_back (111); @@ -50,6 +52,8 @@ main (int argc, char* argv[]) o1.strs_.push_back ("base o1o1o1 two"); object2 o2; + o2.comp_.bools.push_back (true); + o2.comp_.bools.push_back (false); o2.comp_.num = 12; o2.comp_.str = "comp o2o2o2"; o2.comp_.nums.push_back (121); diff --git a/common/inheritance/test.hxx b/common/inheritance/test.hxx index e27ff7a..31ef9c1 100644 --- a/common/inheritance/test.hxx +++ b/common/inheritance/test.hxx @@ -12,7 +12,19 @@ #include #pragma db value -struct comp +struct comp_base +{ + std::vector bools; + + bool + operator== (const comp_base& y) const + { + return bools == y.bools; + } +}; + +#pragma db value +struct comp: comp_base { unsigned int num; std::string str; @@ -22,7 +34,11 @@ struct comp bool operator== (const comp& y) const { - return num == y.num && str == y.str && nums == y.nums; + return + static_cast (*this) == y && + num == y.num && + str == y.str && + nums == y.nums; } }; -- cgit v1.1