OpenMining  0.01
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
find_or_return_default.h
Go to the documentation of this file.
1 /*
2  Copyright 2014 Daniel McInnes
3 
4  This file is part of OpenMining.
5 
6  OpenMining is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  OpenMining is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OpenMining. If not, see <http://www.gnu.org/licenses/>.
18 
19 */
20 
21 #ifndef find_or_return_default_h
22 #define find_or_return_default_h
23 
24 #include <iostream>
25 
26 #include "contains.h"
27 
28 namespace utils
29 {
30  template <class Tcontainer, class Tkey>
31  typename Tcontainer::mapped_type& find_or_return_default(Tcontainer& container, const Tkey& key, Tcontainer& default_return_value)
32  {
33  if (contains(container, key))
34  {
35  std::cout << FN << " found matching value." << std::endl;
36  return container.find(key)->second;
37  }
38  else
39  {
40  std::cout << FN << " no matching value found." << std::endl;
41  return default_return_value.begin()->second;
42  }
43  }
44 }
45 
46 #endif
Tcontainer::mapped_type & find_or_return_default(Tcontainer &container, const Tkey &key, Tcontainer &default_return_value)
Definition: find_or_return_default.h:31
bool contains(Tcontainer &container, Tkey &key)
Definition: contains.h:7
#define FN
Definition: utils.h:42