MEPP2 Project
Helpers.hxx
Go to the documentation of this file.
1 // Copyright (c) 2012-2019 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as
6 // published by the Free Software Foundation; either version 3 of
7 // the License, or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 #pragma once
12 
13 #include <vector>
14 #include <list>
15 #include <set>
16 
17 namespace FEVV {
18 namespace Container {
19 
20 /*
21  * Insert a new element in container.
22  * General case for STL containers.
23  */
24 template< typename ContainerType, typename ContainedType >
25 void
26 insert(ContainerType &container, const ContainedType &element)
27 {
28  container.insert(container.end(), element);
29 }
30 
31 template< typename ContainerType, typename ContainedType >
32 void
33 erase(ContainerType &container, const ContainedType &element)
34 {
35  typename ContainerType::iterator it;
36 
37  if((it = std::find(container.begin(), container.end(), element)) !=
38  container.end())
39  container.erase(it);
40  else
41  throw std::invalid_argument(
42  "Helpers::erase element in container -> given element not found.");
43 }
44 
45 template< typename ContainedType >
46 bool
47 is_sequential_container(const std::vector< ContainedType > &container)
48 {
49  return true;
50 }
51 
52 template< typename ContainedType >
53 bool
54 is_sequential_container(const std::list< ContainedType > &container)
55 {
56  return true;
57 }
58 
59 template< typename ContainedType >
60 bool
61 is_sequential_container(const std::set< ContainedType > &container)
62 {
63  return false;
64 }
65 
66 } // namespace Container
67 } // namespace FEVV
68 
FEVV::Container::insert
void insert(ContainerType &container, const ContainedType &element)
Definition: Helpers.hxx:26
FEVV::Container::is_sequential_container
bool is_sequential_container(const std::vector< ContainedType > &container)
Definition: Helpers.hxx:47
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::Container::erase
void erase(ContainerType &container, const ContainedType &element)
Definition: Helpers.hxx:33