blob: 83890253f9423405ba20e40564f290280c6b2283 [file] [log] [blame]
Junxiao Shi8d71fdb2014-12-07 21:55:19 -07001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
3from waflib.Configure import conf
4
5FRIEND_TYPENAME = '''
6class A;
7
8template<typename T>
9class B
10{
11 friend T;
12};
13
14B<A> g_b;
15'''
16
17FRIEND_WRAPPER = '''
18class A;
19
20template<typename T>
21struct TypeWrapper
22{
23 typedef T Type;
24};
25
26template<typename T>
27class B
28{
29 friend class TypeWrapper<T>::Type;
30};
31
32B<A> g_b;
33'''
34
35@conf
36def check_friend_typename(self):
37 if self.check_cxx(msg='Checking for friend typename-specifier',
38 fragment=FRIEND_TYPENAME,
39 features='cxx', mandatory=False):
40 self.define('HAVE_CXX_FRIEND_TYPENAME', 1)
41 elif self.check_cxx(msg='Checking for friend typename using wrapper',
42 fragment=FRIEND_WRAPPER,
43 features='cxx', mandatory=True):
44 self.define('HAVE_CXX_FRIEND_TYPENAME_WRAPPER', 1)
45
Junxiao Shi895395f2015-03-03 22:38:56 -070046OVERRIDE = '''
47class Base
48{
49 virtual void
50 f(int a);
51};
52
53class Derived : public Base
54{
55 virtual void
56 f(int a) override;
57};
58
59class Final : public Derived
60{
61 virtual void
62 f(int a) final;
63};
64'''
65
66@conf
67def check_override(self):
68 if self.check_cxx(msg='Checking for override and final specifiers',
69 fragment=OVERRIDE,
70 features='cxx', mandatory=False):
71 self.define('HAVE_CXX_OVERRIDE_FINAL', 1)
72
Davide Pesavento96b96af2015-09-19 23:00:40 +020073STD_TO_STRING = '''
74#include <string>
75int
76main(int argc, char** argv)
77{
78 std::string s = std::to_string(0);
79 s = std::to_string(0l);
80 s = std::to_string(0ll);
81 s = std::to_string(0u);
82 s = std::to_string(0ul);
83 s = std::to_string(0ull);
84 s = std::to_string(0.0f);
85 s = std::to_string(0.0);
86 s = std::to_string(0.0l);
87 s.clear();
88 return 0;
89}
90'''
91
92@conf
93def check_std_to_string(self):
94 if self.check_cxx(msg='Checking for std::to_string',
95 fragment=STD_TO_STRING,
96 features='cxx', mandatory=False):
97 self.define('HAVE_STD_TO_STRING', 1)
98
Joao Pereira7476ebf2015-07-07 14:54:39 -040099VECTOR_INSERT_ERASE_CONST_ITERATOR = '''
100#include <vector>
101int
102main()
103{
104 std::vector<int> v;
105 std::vector<int>::const_iterator it = v.cbegin();
106
107 v.insert(it, 2);
108 it = v.cend() - 1;
109 v.erase(it);
110 return 0;
111}
112'''
113
114@conf
115def check_vector_const_iterators(self):
Davide Pesavento96b96af2015-09-19 23:00:40 +0200116 if self.check_cxx(msg='Checking for std::vector::insert with const_iterator',
Joao Pereira7476ebf2015-07-07 14:54:39 -0400117 fragment=VECTOR_INSERT_ERASE_CONST_ITERATOR,
118 features='cxx', mandatory=False):
Davide Pesavento96b96af2015-09-19 23:00:40 +0200119 self.define('HAVE_VECTOR_INSERT_ERASE_CONST_ITERATOR', 1)
Joao Pereira7476ebf2015-07-07 14:54:39 -0400120
Junxiao Shi8d71fdb2014-12-07 21:55:19 -0700121def configure(conf):
122 conf.check_friend_typename()
Junxiao Shi895395f2015-03-03 22:38:56 -0700123 conf.check_override()
Davide Pesavento96b96af2015-09-19 23:00:40 +0200124 conf.check_std_to_string()
Joao Pereira7476ebf2015-07-07 14:54:39 -0400125 conf.check_vector_const_iterators()