From 3e0ec6220c1bcc32f45ffd26c08b99af556a8101 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 11 Sep 2011 11:01:03 +0200 Subject: Return reference to newly set value from compiler::context::set() --- cutl/compiler/context.hxx | 6 +++--- cutl/compiler/context.txx | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'cutl') diff --git a/cutl/compiler/context.hxx b/cutl/compiler/context.hxx index c8e35e6..6a861e4 100644 --- a/cutl/compiler/context.hxx +++ b/cutl/compiler/context.hxx @@ -88,14 +88,14 @@ namespace cutl get (std::string const& key, X const& default_value) const; template - void + X& set (char const* key, X const& value) { - set (std::string (key), value); + return set (std::string (key), value); } template - void + X& set (std::string const& key, X const& value); void diff --git a/cutl/compiler/context.txx b/cutl/compiler/context.txx index 6c69d0a..2518019 100644 --- a/cutl/compiler/context.txx +++ b/cutl/compiler/context.txx @@ -65,7 +65,7 @@ namespace cutl } template - void context:: + X& context:: set (std::string const& key, X const& value) { try @@ -73,8 +73,12 @@ namespace cutl std::pair r ( map_.insert (map::value_type (key, value))); + X& x (r.first->second. template value ()); + if (!r.second) - r.first->second. template value () = value; + x = value; + + return x; } catch (container::any::typing const&) { -- cgit v1.1