SuperTuxKart
cpp2011.hpp
1 // SuperTuxKart - a fun racing game with go-kart
2 // Copyright (C) 2014-2015 SuperTuxKart-Team
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 3
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 
18 #ifndef CPP2011_HPP
19 #define CPP2011_HPP
20 #include <vector>
21 #if __cplusplus >= 201103 || _MSC_VER >=1800
22 
23  #define OVERRIDE override
24 
25 #else
26 
27  #define OVERRIDE
28 
29 #endif
30 
31 #if (__cplusplus >= 201103 || _MSC_VER >=1800) && !(defined(__clang__) && defined(__APPLE__))
32 #define STDCPP2011
33 #else
34 #define STDCPP2003
35 #endif
36 
37 
38 template<typename T, typename... Args>
39 void pushVector(std::vector<T> *vec, Args ...args)
40 {
41 #ifdef STDCPP2003
42  vec->push_back(T(args...));
43 #else
44  vec->emplace_back(args...);
45 #endif
46 }
47 
48 struct Util
49 {
50  template <typename T>
51  static void populate(std::vector<T> &v)
52  { }
53 
54  template <typename T, typename...Args>
55  static void populate(std::vector<T> &v, T t, Args... args)
56  {
57  v.push_back(t);
58  populate<T>(v, args...);
59  }
60 };
61 
62 
63 template<typename T, typename...Args>
64 static std::vector<T> createVector(Args...args)
65 {
66  std::vector<T> result = std::vector<T>();
67  Util::template populate<T>(result, args...);
68  return result;
69 }
70 
71 #endif
Definition: cpp2011.hpp:49