File tree 10 files changed +132
-1
lines changed
10 files changed +132
-1
lines changed Original file line number Diff line number Diff line change 35
35
a.out
36
36
* .swp
37
37
* .pb. *
38
+ example_ * _cpp *
Original file line number Diff line number Diff line change
1
+ sub_dirs =$(wildcard section[0-3])
2
+
3
+ sub_builds =$(addprefix build_,$(sub_dirs ) )
4
+ sub_cleans =$(addprefix clean_,$(sub_dirs ) )
5
+
6
+ all : $(sub_builds )
7
+
8
+ clean : $(sub_cleans )
9
+
10
+ build_% : %
11
+ make -C $^
12
+
13
+ clean_% : %
14
+ make -C $^ clean
Original file line number Diff line number Diff line change 1
1
# cpp_study
2
2
3
- 《C++实践经验谈》(delayed to May ) Follow me to study modern C++.
3
+ [ 《C++实战笔记》 ] ( https://time.geekbang.org/column/intro/309 ) Follow me to study modern C++.
4
4
5
5
Pull requests of make/cmake are welcome!
6
6
Original file line number Diff line number Diff line change
1
+ CXX_FLAGS =-Wall
2
+ CXX =g++
3
+
4
+ HAS_CPP14 =$(shell \
5
+ echo > /tmp/dummy.cpp ; \
6
+ if $(CXX ) -std=c++14 -c -o /dev/null /tmp/dummy.cpp 2>/dev/null ; then \
7
+ echo yes ; \
8
+ else \
9
+ echo no ; \
10
+ fi)
11
+
12
+ HAS_CPP11 =$(shell \
13
+ echo > /tmp/dummy.cpp ; \
14
+ if $(CXX ) -std=c++11 -c -o /dev/null /tmp/dummy.cpp 2>/dev/null ; then \
15
+ echo yes ; \
16
+ else \
17
+ echo no ; \
18
+ fi)
19
+
20
+ ifeq ($(HAS_CPP14 ) , yes)
21
+ PREFER_STANDARD:=cpp14
22
+ else
23
+ ifeq ($(HAS_CPP11 ) , yes)
24
+ PREFER_STANDARD:=cpp11
25
+ endif
26
+ endif
27
+
28
+ all : examples
29
+
30
+ example_% _cpp14 : % .cpp
31
+ $(CXX ) -std=c++14 -o $@ $^ $(CXX_FLAGS ) $($@ _cxx_flags) $($@ _ld_flags)
32
+
33
+ example_% _cpp11 : % .cpp
34
+ $(CXX ) -std=c++11 -o $@ $^ $(CXX_FLAGS ) $($@ _cxx_flags) $($@ _ld_flags)
35
+
36
+ example_% _cpp98 : % .cpp
37
+ $(CXX ) -std=c++98 -o $@ $^ $(CXX_FLAGS ) $($@ _cxx_flags) $($@ _ld_flags)
38
+
39
+ clean :
40
+ rm -fr example_*
Original file line number Diff line number Diff line change
1
+ include ../common.mk
2
+
3
+ ifeq ($(HAS_CPP14 ) , yes)
4
+ examples : example_test_cpp14
5
+ endif
6
+
7
+ ifeq ($(HAS_CPP11 ) , yes)
8
+ examples : example_test_cpp11
9
+ endif
Original file line number Diff line number Diff line change
1
+ include ../common.mk
2
+
3
+
4
+ ifeq ($(HAS_CPP14 ) , yes)
5
+ examples : \
6
+ example_codestyle_cpp14 \
7
+ example_compile_cpp14 \
8
+ example_oop_cpp14 \
9
+ example_preprocess_cpp14
10
+ endif
11
+
12
+ ifeq ($(HAS_CPP11 ) , yes)
13
+ examples : \
14
+ example_codestyle_cpp11 \
15
+ example_compile_cpp11 \
16
+ example_oop_cpp11 \
17
+ example_preprocess_cpp11
18
+ endif
19
+
20
+ # example_preprocess_cpp98 is showing version check with compile failed.
21
+ # please explicit using `make example_preprocess_cpp98` under section1 folder
Original file line number Diff line number Diff line change 7
7
//
8
8
// gcc -E -dM - < /dev/null
9
9
10
+ #include < cassert>
11
+
10
12
#include < typeinfo>
13
+ #include < string>
11
14
#include < iostream>
12
15
#include < stdexcept>
13
16
#include < type_traits>
@@ -123,6 +126,18 @@ void check_type(T v)
123
126
cout << is_void<void >::value << endl;
124
127
}
125
128
129
+ void case5 ()
130
+ {
131
+ int i = 10 ;
132
+ int *p = &i;
133
+
134
+ assert (i > 0 && " i must be greater than zero" );
135
+ assert (p != nullptr );
136
+
137
+ std::string str = " hello" ;
138
+ assert (!str.empty ());
139
+ }
140
+
126
141
int main ()
127
142
{
128
143
using namespace std ;
@@ -141,6 +156,7 @@ int main()
141
156
case3 ();
142
157
143
158
case4 ();
159
+ case5 ();
144
160
145
161
check_type (10 );
146
162
// check_type((void*)0);
Original file line number Diff line number Diff line change @@ -122,6 +122,8 @@ int main()
122
122
case2 ();
123
123
124
124
my_own::case3 ();
125
+
126
+ [[gnu::unused]] // ignore warning
125
127
my_own::MyClass obj;
126
128
127
129
case4 ();
Original file line number Diff line number Diff line change
1
+ include ../common.mk
2
+
3
+ ifeq ($(HAS_CPP14 ) , yes)
4
+ examples : \
5
+ example_auto_cpp14 \
6
+ example_const_cpp14 \
7
+ example_exception_cpp14 \
8
+ example_lambda_cpp14 \
9
+ example_smart_ptr_cpp14
10
+ endif
11
+
12
+ ifeq ($(HAS_CPP11 ) , yes)
13
+ examples : \
14
+ example_exception_cpp11
15
+ endif
Original file line number Diff line number Diff line change
1
+ include ../common.mk
2
+
3
+ example_thread_cpp14_ld_flags =-lpthread
4
+ example_thread_cpp11_ld_flags =-lpthread
5
+
6
+
7
+ ifeq ($(HAS_CPP14 ) , yes)
8
+ examples : \
9
+ example_algo_cpp14 \
10
+ example_container_cpp14 \
11
+ example_string_cpp14 \
12
+ example_thread_cpp14
13
+ endif
You can’t perform that action at this time.
0 commit comments