Changeset 3253
- Timestamp:
- Jun 8, 2014, 1:48:42 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/utility.cc
r3238 r3253 301 301 suite.out() << "expected exception thrown with what() = " 302 302 << e.what() << "\n"; 303 } 304 // don't run compiler test code 305 if (false) { 306 typedef boost::default_constructible_archetype< 307 boost::sgi_assignable_archetype<> > key_type; 308 309 typedef boost::default_constructible_archetype< 310 boost::sgi_assignable_archetype< 311 boost::null_archetype<std::string> > > value_type; 312 313 typedef boost::default_constructible_archetype< 314 boost::binary_function_archetype<key_type, key_type, bool> > Compare; 315 316 std::map<key_type, value_type, Compare> m3; 317 key_type my_key; 318 utility::get(m3, my_key); 303 319 } 304 320 } -
trunk/yat/utility/stl_utility.h
r3247 r3253 9 9 Copyright (C) 2006 Jari Häkkinen 10 10 Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson 11 Copyright (C) 2009, 2010, 2011, 2012, 2013 Peter Johansson11 Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Peter Johansson 12 12 13 13 This file is part of the yat library, http://dev.thep.lu.se/yat … … 485 485 \return const reference to m[k] 486 486 487 \throw get_error if key \a k does not exist in map 488 487 489 \since New in yat 0.7 488 490 */ … … 490 492 const Tp& get(const std::map<Key, Tp, Compare, Alloc>& m, const Key& k); 491 493 494 /** 495 \brief error class used in 496 get(const std::map<Key, Tp, Compare, Alloc>& m, const Key& k) 497 498 \since yat 0.13 499 */ 500 template<typename Key> 501 class get_error : public runtime_error 502 { 503 public: 504 /// \brief constructor 505 get_error(const std::string& msg, const Key& key) 506 : runtime_error(msg), key_(key) {} 507 /// \brief destructor 508 virtual ~get_error(void) throw () {} 509 /// access the key object 510 const Key& key(void) const { return key_; } 511 private: 512 Key key_; 513 }; 492 514 493 515 /** … … 910 932 typename std::map<Key, Tp, Compare,Alloc>::const_iterator iter(m.find(key)); 911 933 if (iter==m.end()) { 912 std::stringstream ss; 913 ss << "utility::get(const Map&, const Key&): '" 914 << key << "' not found in map\n"; 915 throw runtime_error(ss.str()); 934 throw 935 get_error<Key>("utility::get(const Map&, const Key&): key not found", 936 key); 916 937 } 917 938 return iter->second;
Note: See TracChangeset
for help on using the changeset viewer.