From d3933483fa0d4b3e1d6921b8682c7d5ce7c35da6 Mon Sep 17 00:00:00 2001 From: ATTY Lionel Date: Tue, 10 May 2016 14:05:42 +0200 Subject: [PATCH 01/13] Suppress .user config from QtCreator IDE --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e91e50d..a3bca71 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ CMakeFiles cmake_install.cmake CMakeCache.txt *.so +.gitignore From abe2cddf8c115cc5ba2d2fcfc037c390ff15a841 Mon Sep 17 00:00:00 2001 From: ATTY Lionel Date: Tue, 10 May 2016 14:19:08 +0200 Subject: [PATCH 02/13] =?UTF-8?q?Probl=C3=A8me=20de=20compilation=20avec?= =?UTF-8?q?=20certains=20Items=20sous=20GCC-4.9.=20Desactivation=20des=20t?= =?UTF-8?q?argets=20de=20compilation=20des=20items=20suivants:=20=3D>=2016?= =?UTF-8?q?,=2023,=2027,=2031,=2032,=2033,=2034,=2035,=2036=20Il=20y=20a?= =?UTF-8?q?=20des=20probl=C3=A8mes=20(en=20particulier)=20avec=20la=20lib?= =?UTF-8?q?=20pthread=20(et/ou=20CMake)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- .../CMakeLists.txt | 2 +- .../CMakeLists.txt | 12 ++++---- .../CMakeLists.txt | 22 +++++++------- .../CMakeLists.txt | 6 ++-- .../CMakeLists.txt | 30 +++++++++---------- .../CMakeLists.txt | 4 +-- .../CMakeLists.txt | 30 +++++++++---------- .../CMakeLists.txt | 6 ++-- .../CMakeLists.txt | 18 +++++------ 10 files changed, 66 insertions(+), 66 deletions(-) diff --git a/.gitignore b/.gitignore index a3bca71..3b15271 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ CMakeFiles cmake_install.cmake CMakeCache.txt *.so -.gitignore +CMakeLists.txt.user diff --git a/Item16_Make_const_member_functions_thread-safe/CMakeLists.txt b/Item16_Make_const_member_functions_thread-safe/CMakeLists.txt index 0ee4bcc..ee41462 100644 --- a/Item16_Make_const_member_functions_thread-safe/CMakeLists.txt +++ b/Item16_Make_const_member_functions_thread-safe/CMakeLists.txt @@ -1,4 +1,4 @@ # TODO: complete this CMakeLists.txt #add_executable(insertion_cpp98 insertion_cpp98.cpp) -add_executable(undefined_behavior undefined_behavior.cpp) +#add_executable(undefined_behavior undefined_behavior.cpp) #add_library(roots Polynomial.cpp) diff --git a/Item23_Understand_std_move_and_std_forward/CMakeLists.txt b/Item23_Understand_std_move_and_std_forward/CMakeLists.txt index 88be2c0..12159d0 100644 --- a/Item23_Understand_std_move_and_std_forward/CMakeLists.txt +++ b/Item23_Understand_std_move_and_std_forward/CMakeLists.txt @@ -1,10 +1,10 @@ -set_source_files_properties(std_move_in_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +#set_source_files_properties(std_move_in_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") add_executable(typical_use_of_std_forward typical_use_of_std_forward.cpp) -add_library(item23 std_move_in_cpp11.cpp - std_move_in_cpp14.cpp - annotation.cpp - move_constructor_with_move.cpp - move_constructor_with_forward.cpp) +#add_library(item23 std_move_in_cpp11.cpp +# std_move_in_cpp14.cpp +# annotation.cpp +# move_constructor_with_move.cpp +# move_constructor_with_forward.cpp) diff --git a/Item27_Familiarize_yourself_with_alternatives_to_overloading_on_universal_references/CMakeLists.txt b/Item27_Familiarize_yourself_with_alternatives_to_overloading_on_universal_references/CMakeLists.txt index 3901517..ea25723 100644 --- a/Item27_Familiarize_yourself_with_alternatives_to_overloading_on_universal_references/CMakeLists.txt +++ b/Item27_Familiarize_yourself_with_alternatives_to_overloading_on_universal_references/CMakeLists.txt @@ -1,12 +1,12 @@ -set_source_files_properties(constraining_templates02_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -set_source_files_properties(constraining_templates03_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -set_source_files_properties(constraining_templates04_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +#set_source_files_properties(constraining_templates02_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +#set_source_files_properties(constraining_templates03_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +#set_source_files_properties(constraining_templates04_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -add_library(alternatives_to_uref_overloading alternative_pass_by_value.cpp - tag_dispatch01.cpp - tag_dispatch02.cpp - constraining_templates01.cpp - constraining_templates02_cpp11.cpp - constraining_templates02_cpp14.cpp - constraining_templates03_cpp14.cpp - constraining_templates04_cpp14.cpp) +#add_library(alternatives_to_uref_overloading alternative_pass_by_value.cpp +# tag_dispatch01.cpp +# tag_dispatch02.cpp +# constraining_templates01.cpp +# constraining_templates02_cpp11.cpp +# constraining_templates02_cpp14.cpp +# constraining_templates03_cpp14.cpp +# constraining_templates04_cpp14.cpp) diff --git a/Item31_Avoid_default_capture_modes/CMakeLists.txt b/Item31_Avoid_default_capture_modes/CMakeLists.txt index 097fe5a..3da73c6 100644 --- a/Item31_Avoid_default_capture_modes/CMakeLists.txt +++ b/Item31_Avoid_default_capture_modes/CMakeLists.txt @@ -1,4 +1,4 @@ -set_source_files_properties(by_reference_capture.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +#set_source_files_properties(by_reference_capture.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -add_executable(by_reference_capture - Widget.cpp by_reference_capture.cpp) +#add_executable(by_reference_capture +# Widget.cpp by_reference_capture.cpp) diff --git a/Item32_Use_init_capture_to_move_objects_into_closures/CMakeLists.txt b/Item32_Use_init_capture_to_move_objects_into_closures/CMakeLists.txt index 3ea74fe..7051607 100644 --- a/Item32_Use_init_capture_to_move_objects_into_closures/CMakeLists.txt +++ b/Item32_Use_init_capture_to_move_objects_into_closures/CMakeLists.txt @@ -1,20 +1,20 @@ -set_source_files_properties(init_capture_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -add_executable(init_capture_cpp14 - init_capture_cpp14.cpp) +#set_source_files_properties(init_capture_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +#add_executable(init_capture_cpp14 +# init_capture_cpp14.cpp) -set_source_files_properties(init_capture_cpp11.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -add_executable(init_capture_cpp11 - init_capture_cpp11.cpp - Widget.cpp) +#set_source_files_properties(init_capture_cpp11.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +#add_executable(init_capture_cpp11 +# init_capture_cpp11.cpp +# Widget.cpp) -set_source_files_properties(move_capture1_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -add_executable(move_capture1_cpp14 - move_capture1_cpp14.cpp) +#set_source_files_properties(move_capture1_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +#add_executable(move_capture1_cpp14 +# move_capture1_cpp14.cpp) -add_executable(move_capture1_cpp11 - move_capture1_cpp11.cpp) +#add_executable(move_capture1_cpp11 +# move_capture1_cpp11.cpp) -set_source_files_properties(move_capture2.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -add_executable(move_capture2 - move_capture2.cpp) +#set_source_files_properties(move_capture2.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +#add_executable(move_capture2 +# move_capture2.cpp) diff --git a/Item33_Use_decltype_on_autorr_parameters_to_std_forward_them/CMakeLists.txt b/Item33_Use_decltype_on_autorr_parameters_to_std_forward_them/CMakeLists.txt index 4ff47a7..0969242 100644 --- a/Item33_Use_decltype_on_autorr_parameters_to_std_forward_them/CMakeLists.txt +++ b/Item33_Use_decltype_on_autorr_parameters_to_std_forward_them/CMakeLists.txt @@ -1,2 +1,2 @@ -set_source_files_properties(item35.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -add_executable(item35 item35.cpp) +#set_source_files_properties(item35.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +#add_executable(item35 item35.cpp) diff --git a/Item34_Prefer_lambdas_to_std_bind/CMakeLists.txt b/Item34_Prefer_lambdas_to_std_bind/CMakeLists.txt index 1f0b648..ed6b7f7 100644 --- a/Item34_Prefer_lambdas_to_std_bind/CMakeLists.txt +++ b/Item34_Prefer_lambdas_to_std_bind/CMakeLists.txt @@ -1,37 +1,37 @@ add_executable(alarm_with_lambda_cpp11 alarm_with_lambda_cpp11.cpp) -set_source_files_properties(alarm_with_lambda_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -add_executable(alarm_with_lambda_cpp14 alarm_with_lambda_cpp14.cpp) +#set_source_files_properties(alarm_with_lambda_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +#add_executable(alarm_with_lambda_cpp14 alarm_with_lambda_cpp14.cpp) -set_source_files_properties(alarm_with_lambda_and_overload_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -add_executable(alarm_with_lambda_and_overload_cpp14 alarm_with_lambda_and_overload_cpp14.cpp) +#set_source_files_properties(alarm_with_lambda_and_overload_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +#add_executable(alarm_with_lambda_and_overload_cpp14 alarm_with_lambda_and_overload_cpp14.cpp) add_executable(alarm_with_std_bind_incorrect alarm_with_std_bind_incorrect.cpp) add_executable(alarm_with_std_bind_cpp11 alarm_with_std_bind_cpp11.cpp) -set_source_files_properties(alarm_with_std_bind_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -add_executable(alarm_with_std_bind_cpp14 alarm_with_std_bind_cpp14.cpp) +#set_source_files_properties(alarm_with_std_bind_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +#add_executable(alarm_with_std_bind_cpp14 alarm_with_std_bind_cpp14.cpp) -set_source_files_properties(alarm_with_std_bind_and_overload_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -add_executable(alarm_with_std_bind_and_overload_cpp14 alarm_with_std_bind_and_overload_cpp14.cpp) +#set_source_files_properties(alarm_with_std_bind_and_overload_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +#add_executable(alarm_with_std_bind_and_overload_cpp14 alarm_with_std_bind_and_overload_cpp14.cpp) add_executable(between_with_lambda_cpp11 between_with_lambda_cpp11.cpp) -set_source_files_properties(between_with_lambda_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -add_executable(between_with_lambda_cpp14 between_with_lambda_cpp14.cpp) +#set_source_files_properties(between_with_lambda_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +#add_executable(between_with_lambda_cpp14 between_with_lambda_cpp14.cpp) -add_executable(between_with_std_bind_cpp11 between_with_std_bind_cpp11.cpp) +#add_executable(between_with_std_bind_cpp11 between_with_std_bind_cpp11.cpp) -set_source_files_properties(between_with_std_bind_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -add_executable(between_with_std_bind_cpp14 between_with_std_bind_cpp14.cpp) +#set_source_files_properties(between_with_std_bind_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +#add_executable(between_with_std_bind_cpp14 between_with_std_bind_cpp14.cpp) add_executable(compress_with_lambda compress_with_lambda.cpp) add_executable(compress_with_std_bind compress_with_std_bind.cpp) -set_source_files_properties(polymorphic_function_objects_with_lambda_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -add_executable(polymorphic_function_objects_with_lambda_cpp14 polymorphic_function_objects_with_lambda_cpp14.cpp) +#set_source_files_properties(polymorphic_function_objects_with_lambda_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +#add_executable(polymorphic_function_objects_with_lambda_cpp14 polymorphic_function_objects_with_lambda_cpp14.cpp) add_executable(polymorphic_function_objects_with_std_bind polymorphic_function_objects_with_std_bind.cpp) diff --git a/Item35_Prefer_task-based_programming_to_thread-based/CMakeLists.txt b/Item35_Prefer_task-based_programming_to_thread-based/CMakeLists.txt index 637463f..782ef5c 100644 --- a/Item35_Prefer_task-based_programming_to_thread-based/CMakeLists.txt +++ b/Item35_Prefer_task-based_programming_to_thread-based/CMakeLists.txt @@ -1,3 +1,3 @@ -add_executable(software_threads software_threads.cpp) -add_executable(task_based_approach task_based_approach.cpp) -add_executable(thread_based_approach thread_based_approach.cpp) +#add_executable(software_threads software_threads.cpp) +#add_executable(task_based_approach task_based_approach.cpp) +#add_executable(thread_based_approach thread_based_approach.cpp) diff --git a/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/CMakeLists.txt b/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/CMakeLists.txt index 0f02f53..43f0fc8 100644 --- a/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/CMakeLists.txt +++ b/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/CMakeLists.txt @@ -1,16 +1,16 @@ -add_executable(default_launch_policy default_launch_policy.cpp) +#add_executable(default_launch_policy default_launch_policy.cpp) -add_executable(guaranteeing_truly_asynchronous_execution guaranteeing_truly_asynchronous_execution.cpp) +#add_executable(guaranteeing_truly_asynchronous_execution guaranteeing_truly_asynchronous_execution.cpp) -add_executable(interesting_implications interesting_implications.cpp) +#add_executable(interesting_implications interesting_implications.cpp) -add_executable(really_async_cpp11 really_async_cpp11.cpp) +#add_executable(really_async_cpp11 really_async_cpp11.cpp) -set_source_files_properties(really_async_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -add_executable(really_async_cpp14 really_async_cpp14.cpp) +#set_source_files_properties(really_async_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +#add_executable(really_async_cpp14 really_async_cpp14.cpp) -add_executable(thread_local_storage thread_local_storage.cpp) +#add_executable(thread_local_storage thread_local_storage.cpp) -add_executable(wait-based_loops wait-based_loops.cpp) +#add_executable(wait-based_loops wait-based_loops.cpp) -add_executable(wait-based_loops_fixed wait-based_loops_fixed.cpp) +#add_executable(wait-based_loops_fixed wait-based_loops_fixed.cpp) From 8a7935ca9dc772a2a017b5dccb74da3a0ce3f7c0 Mon Sep 17 00:00:00 2001 From: ATTY Lionel Date: Tue, 10 May 2016 14:36:07 +0200 Subject: [PATCH 03/13] Modification de l'Item13 pour faire tourner les samples C++11 et 14 --- .../CMakeLists.txt | 5 +++++ .../insertion_cpp14.cpp | 19 ++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Item13_Prefer_const_iterators_to_iterators/CMakeLists.txt b/Item13_Prefer_const_iterators_to_iterators/CMakeLists.txt index c0282cd..da33fe1 100644 --- a/Item13_Prefer_const_iterators_to_iterators/CMakeLists.txt +++ b/Item13_Prefer_const_iterators_to_iterators/CMakeLists.txt @@ -1,3 +1,8 @@ add_executable(insertion_cpp98 insertion_cpp98.cpp) + # TODO: find out why this doesn't compile!!! add_executable(insertion_cpp11 insertion_cpp11.cpp) +add_executable(insertion_cpp11 insertion_cpp11.cpp) # work on gcc-4.9 + # TODO add_executable(insertion_cpp11 insertion_cpp14.cpp) +#set_source_files_properties(insertion_cpp14.cpp PROPERTIES COMPILE_FLAGS -std=c++14) +add_executable(insertion_cpp14 insertion_cpp14.cpp) diff --git a/Item13_Prefer_const_iterators_to_iterators/insertion_cpp14.cpp b/Item13_Prefer_const_iterators_to_iterators/insertion_cpp14.cpp index 9252af3..bec814c 100644 --- a/Item13_Prefer_const_iterators_to_iterators/insertion_cpp14.cpp +++ b/Item13_Prefer_const_iterators_to_iterators/insertion_cpp14.cpp @@ -17,11 +17,20 @@ void findAndInsert(C& container, // in container, find const V& targetVal, // first occurrence const V& insertVal) // of targetVal, then { // insert insertVal - using std::cbegin; // there - using std::cend; +// using std::cbegin; // there +// using std::cend; - auto it = std::find(cbegin(container), // non-member cbegin - cend(container), // non-member cend +// auto it = std::find(cbegin(container), // non-member cbegin +// cend(container), // non-member cend +// targetVal); + + // Support of `std::cbegin()`in C++14 + // url: http://stackoverflow.com/a/31038315 + using std::begin; // there + using std::end; + + auto it = std::find(begin(container), // non-member cbegin + end(container), // non-member cend targetVal); container.insert(it, insertVal); @@ -32,6 +41,6 @@ int main() std::vector values; // as before - findAndInsert(values, 1983, 1998) + findAndInsert(values, 1983, 1998); } From e559023b821515d16338b3a84e083e4ad184c9b3 Mon Sep 17 00:00:00 2001 From: ATTY Lionel Date: Tue, 10 May 2016 14:44:59 +0200 Subject: [PATCH 04/13] =?UTF-8?q?Fix=20pour=20faire=20tourner=20l'Item16?= =?UTF-8?q?=20(pthread).=20TODO:=20=C3=A0=20revoir,=20ce=20n'est=20pas=20t?= =?UTF-8?q?r=C3=A8s=20propre=20(trop=20direct=20pas=20modulable/flexible)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 2 +- .../CMakeLists.txt | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd73fdc..d5ba95e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 2.6) -project(Effective_Modern_C++ CXX) +project(Effective_Modern_C++ CXX C) # Uncomment this to use clang++ to compile. #SET (CMAKE_CXX_COMPILER "/usr/bin/clang++-3.5") diff --git a/Item16_Make_const_member_functions_thread-safe/CMakeLists.txt b/Item16_Make_const_member_functions_thread-safe/CMakeLists.txt index ee41462..2b75571 100644 --- a/Item16_Make_const_member_functions_thread-safe/CMakeLists.txt +++ b/Item16_Make_const_member_functions_thread-safe/CMakeLists.txt @@ -1,4 +1,10 @@ # TODO: complete this CMakeLists.txt -#add_executable(insertion_cpp98 insertion_cpp98.cpp) -#add_executable(undefined_behavior undefined_behavior.cpp) + +add_executable(expensive_int expensive_int.cpp) + +add_executable(undefined_behavior undefined_behavior.cpp) + +# pas très propre, faudrait une version avec cmake ... +target_link_libraries (undefined_behavior pthread) + #add_library(roots Polynomial.cpp) From d501bb0dadae01decb00eb7f81eec775e03db466 Mon Sep 17 00:00:00 2001 From: ATTY Lionel Date: Tue, 10 May 2016 15:06:21 +0200 Subject: [PATCH 05/13] =?UTF-8?q?Items:=2023=2027=2031=20Fix=20pour=20comp?= =?UTF-8?q?ilation=20sous=20GCC-4.9=20Plus=20de=20travail=20pour=20le=2031?= =?UTF-8?q?:=20Ajout=20d'une=20classe=20singleton=20pour=20g=C3=A9rer=20un?= =?UTF-8?q?=20pb=20de=20doublon=20d'object=20dans=20le=20header=20utilitai?= =?UTF-8?q?re=20'utils.h'.=20Ca=20permet=20de=20g=C3=A9n=C3=A9rer=20qu'un?= =?UTF-8?q?=20object=20'filters'=20r=C3=A9cup=C3=A9rables=20maintenant=20p?= =?UTF-8?q?ar=20le=20singleton=20associ=C3=A9=20=C3=A0=20une=20classe=20d?= =?UTF-8?q?=C3=A9di=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CMakeLists.txt | 11 +++-- .../CMakeLists.txt | 20 +++++--- .../CMakeLists.txt | 6 ++- Item31_Avoid_default_capture_modes/Widget.cpp | 2 + .../by_reference_capture.cpp | 6 +++ Item31_Avoid_default_capture_modes/utils.h | 49 +++++++++++++++++-- 6 files changed, 76 insertions(+), 18 deletions(-) diff --git a/Item23_Understand_std_move_and_std_forward/CMakeLists.txt b/Item23_Understand_std_move_and_std_forward/CMakeLists.txt index 12159d0..f63785d 100644 --- a/Item23_Understand_std_move_and_std_forward/CMakeLists.txt +++ b/Item23_Understand_std_move_and_std_forward/CMakeLists.txt @@ -1,10 +1,11 @@ #set_source_files_properties(std_move_in_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +set_source_files_properties(std_move_in_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") add_executable(typical_use_of_std_forward typical_use_of_std_forward.cpp) -#add_library(item23 std_move_in_cpp11.cpp -# std_move_in_cpp14.cpp -# annotation.cpp -# move_constructor_with_move.cpp -# move_constructor_with_forward.cpp) +add_library(item23 std_move_in_cpp11.cpp + std_move_in_cpp14.cpp + annotation.cpp + move_constructor_with_move.cpp + move_constructor_with_forward.cpp) diff --git a/Item27_Familiarize_yourself_with_alternatives_to_overloading_on_universal_references/CMakeLists.txt b/Item27_Familiarize_yourself_with_alternatives_to_overloading_on_universal_references/CMakeLists.txt index ea25723..9591586 100644 --- a/Item27_Familiarize_yourself_with_alternatives_to_overloading_on_universal_references/CMakeLists.txt +++ b/Item27_Familiarize_yourself_with_alternatives_to_overloading_on_universal_references/CMakeLists.txt @@ -2,11 +2,15 @@ #set_source_files_properties(constraining_templates03_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") #set_source_files_properties(constraining_templates04_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -#add_library(alternatives_to_uref_overloading alternative_pass_by_value.cpp -# tag_dispatch01.cpp -# tag_dispatch02.cpp -# constraining_templates01.cpp -# constraining_templates02_cpp11.cpp -# constraining_templates02_cpp14.cpp -# constraining_templates03_cpp14.cpp -# constraining_templates04_cpp14.cpp) +set_source_files_properties(constraining_templates02_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") +set_source_files_properties(constraining_templates03_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") +set_source_files_properties(constraining_templates04_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") + +add_library(alternatives_to_uref_overloading alternative_pass_by_value.cpp + tag_dispatch01.cpp + tag_dispatch02.cpp + constraining_templates01.cpp + constraining_templates02_cpp11.cpp + constraining_templates02_cpp14.cpp + constraining_templates03_cpp14.cpp + constraining_templates04_cpp14.cpp) diff --git a/Item31_Avoid_default_capture_modes/CMakeLists.txt b/Item31_Avoid_default_capture_modes/CMakeLists.txt index 3da73c6..e53842d 100644 --- a/Item31_Avoid_default_capture_modes/CMakeLists.txt +++ b/Item31_Avoid_default_capture_modes/CMakeLists.txt @@ -1,4 +1,6 @@ #set_source_files_properties(by_reference_capture.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +set_source_files_properties(by_reference_capture.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") +set_source_files_properties(Widget.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") -#add_executable(by_reference_capture -# Widget.cpp by_reference_capture.cpp) +add_executable(by_reference_capture + Widget.cpp by_reference_capture.cpp) diff --git a/Item31_Avoid_default_capture_modes/Widget.cpp b/Item31_Avoid_default_capture_modes/Widget.cpp index 2001f81..d48ac70 100644 --- a/Item31_Avoid_default_capture_modes/Widget.cpp +++ b/Item31_Avoid_default_capture_modes/Widget.cpp @@ -3,6 +3,8 @@ void Widget::addFilter() const { + Filters::FilterContainer& filters = Filters::get_instance()->filters; + // default by-value capture filters.emplace_back( [=](int value) { return value % divisor == 0; } diff --git a/Item31_Avoid_default_capture_modes/by_reference_capture.cpp b/Item31_Avoid_default_capture_modes/by_reference_capture.cpp index 77beb5c..5cfc45a 100644 --- a/Item31_Avoid_default_capture_modes/by_reference_capture.cpp +++ b/Item31_Avoid_default_capture_modes/by_reference_capture.cpp @@ -34,6 +34,8 @@ void addDivisorFilter() auto divisor = computeDivisor(calc1, calc2); + Filters::FilterContainer& filters = Filters::get_instance()->filters; + filters.emplace_back( // danger! [&](int value) { return value % divisor == 0; } // ref to // divisor @@ -60,6 +62,8 @@ void addDivisorFilter2() static auto divisor = // now static computeDivisor(calc1, calc2); + Filters::FilterContainer& filters = Filters::get_instance()->filters; + filters.emplace_back( [=](int value) // captures nothing! { return value % divisor == 0; } // refers to above static @@ -120,6 +124,8 @@ void doSomeWork() int main() { + Filters::FilterContainer& filters = Filters::get_instance()->filters; + filters.emplace_back( // see Item 42 for [](int value) { return value % 5 == 0; } // info on ); // emplace_back diff --git a/Item31_Avoid_default_capture_modes/utils.h b/Item31_Avoid_default_capture_modes/utils.h index db8351e..8c8e71d 100644 --- a/Item31_Avoid_default_capture_modes/utils.h +++ b/Item31_Avoid_default_capture_modes/utils.h @@ -4,10 +4,53 @@ #include #include -using FilterContainer = // see Item 9 for +#include + +// url: http://enki-tech.blogspot.fr/2012/08/c11-generic-singleton.html +template +class Singleton +{ +public: + template + static + T* get_instance(Args... args) + { + if (!instance_) + { + instance_ = new T(std::forward(args)...); + } + + return instance_; + } + + static + void destroy_instance() + { + delete instance_; + instance_ = nullptr; + } + +private: + static T* instance_; +}; + +template T* Singleton::instance_ = nullptr; + +class Filters: public Singleton +{ + friend class Singleton; + +private: + Filters() {} + +public: + using FilterContainer = // see Item 9 for std::vector>; // "using", Item 2 - // for std::function + // for std::function + + FilterContainer filters; +}; -FilterContainer filters; // filtering funcs +// filtering funcs #endif /* UTILS_H */ From e64fd808446dbb4e455ff843769944d249adf0d4 Mon Sep 17 00:00:00 2001 From: ATTY Lionel Date: Tue, 10 May 2016 15:24:38 +0200 Subject: [PATCH 06/13] =?UTF-8?q?Items:=2032=2033=2036=20Fix,=20r=C3=A9?= =?UTF-8?q?=C3=A9criture=20des=20CMake=20et=20partiellement=20fix=20de=20c?= =?UTF-8?q?ode=20(36=20manquait=20des=20points=20virgules,=20bizarre)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CMakeLists.txt | 30 ++++++++--------- .../CMakeLists.txt | 4 +-- .../CMakeLists.txt | 32 +++++++++++++------ .../wait-based_loops.cpp | 2 +- .../wait-based_loops_fixed.cpp | 2 +- 5 files changed, 42 insertions(+), 28 deletions(-) diff --git a/Item32_Use_init_capture_to_move_objects_into_closures/CMakeLists.txt b/Item32_Use_init_capture_to_move_objects_into_closures/CMakeLists.txt index 7051607..b8679da 100644 --- a/Item32_Use_init_capture_to_move_objects_into_closures/CMakeLists.txt +++ b/Item32_Use_init_capture_to_move_objects_into_closures/CMakeLists.txt @@ -1,20 +1,20 @@ -#set_source_files_properties(init_capture_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -#add_executable(init_capture_cpp14 -# init_capture_cpp14.cpp) +set_source_files_properties(init_capture_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") +add_executable(init_capture_cpp14 + init_capture_cpp14.cpp) -#set_source_files_properties(init_capture_cpp11.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -#add_executable(init_capture_cpp11 -# init_capture_cpp11.cpp -# Widget.cpp) +set_source_files_properties(init_capture_cpp11.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") +add_executable(init_capture_cpp11 + init_capture_cpp11.cpp + Widget.cpp) -#set_source_files_properties(move_capture1_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -#add_executable(move_capture1_cpp14 -# move_capture1_cpp14.cpp) +set_source_files_properties(move_capture1_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") +add_executable(move_capture1_cpp14 + move_capture1_cpp14.cpp) -#add_executable(move_capture1_cpp11 -# move_capture1_cpp11.cpp) +add_executable(move_capture1_cpp11 + move_capture1_cpp11.cpp) -#set_source_files_properties(move_capture2.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -#add_executable(move_capture2 -# move_capture2.cpp) +set_source_files_properties(move_capture2.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") +add_executable(move_capture2 + move_capture2.cpp) diff --git a/Item33_Use_decltype_on_autorr_parameters_to_std_forward_them/CMakeLists.txt b/Item33_Use_decltype_on_autorr_parameters_to_std_forward_them/CMakeLists.txt index 0969242..a4f588b 100644 --- a/Item33_Use_decltype_on_autorr_parameters_to_std_forward_them/CMakeLists.txt +++ b/Item33_Use_decltype_on_autorr_parameters_to_std_forward_them/CMakeLists.txt @@ -1,2 +1,2 @@ -#set_source_files_properties(item35.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -#add_executable(item35 item35.cpp) +set_source_files_properties(item35.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") +add_executable(item35 item35.cpp) diff --git a/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/CMakeLists.txt b/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/CMakeLists.txt index 43f0fc8..6efa6a5 100644 --- a/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/CMakeLists.txt +++ b/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/CMakeLists.txt @@ -1,16 +1,30 @@ -#add_executable(default_launch_policy default_launch_policy.cpp) +add_executable(default_launch_policy default_launch_policy.cpp) +# pas très propre, faudrait une version avec cmake ... +target_link_libraries (default_launch_policy pthread) -#add_executable(guaranteeing_truly_asynchronous_execution guaranteeing_truly_asynchronous_execution.cpp) +add_executable(guaranteeing_truly_asynchronous_execution guaranteeing_truly_asynchronous_execution.cpp) +# pas très propre, faudrait une version avec cmake ... +target_link_libraries(guaranteeing_truly_asynchronous_execution pthread) -#add_executable(interesting_implications interesting_implications.cpp) +add_executable(interesting_implications interesting_implications.cpp) +# pas très propre, faudrait une version avec cmake ... +target_link_libraries(interesting_implications pthread) -#add_executable(really_async_cpp11 really_async_cpp11.cpp) +add_executable(really_async_cpp11 really_async_cpp11.cpp) +target_link_libraries(really_async_cpp11 pthread) -#set_source_files_properties(really_async_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -#add_executable(really_async_cpp14 really_async_cpp14.cpp) +set_source_files_properties(really_async_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") +add_executable(really_async_cpp14 really_async_cpp14.cpp) +target_link_libraries(really_async_cpp14 pthread) -#add_executable(thread_local_storage thread_local_storage.cpp) +add_executable(thread_local_storage thread_local_storage.cpp) +target_link_libraries(thread_local_storage pthread) -#add_executable(wait-based_loops wait-based_loops.cpp) +# url: http://stackoverflow.com/questions/35856969/chrono-literals-is-not-a-namespace-name +set_source_files_properties(wait-based_loops.cpp PROPERTIES COMPILE_FLAGS "-std=gnu++14 -std=c++14") +add_executable(wait-based_loops wait-based_loops.cpp) +target_link_libraries(wait-based_loops pthread) -#add_executable(wait-based_loops_fixed wait-based_loops_fixed.cpp) +set_source_files_properties(wait-based_loops_fixed.cpp PROPERTIES COMPILE_FLAGS "-std=gnu++14 -std=c++14") +add_executable(wait-based_loops_fixed wait-based_loops_fixed.cpp) +target_link_libraries(wait-based_loops_fixed pthread) diff --git a/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/wait-based_loops.cpp b/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/wait-based_loops.cpp index 0e58985..9879afd 100644 --- a/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/wait-based_loops.cpp +++ b/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/wait-based_loops.cpp @@ -19,7 +19,7 @@ void f() // f sleeps for 1 second, int main() { - auto fut = std::async(f) // run f asynchronously + auto fut = std::async(f); // run f asynchronously // (conceptually) while (fut.wait_for(100ms) != // loop until f has diff --git a/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/wait-based_loops_fixed.cpp b/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/wait-based_loops_fixed.cpp index 804a7b4..740566a 100644 --- a/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/wait-based_loops_fixed.cpp +++ b/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/wait-based_loops_fixed.cpp @@ -17,7 +17,7 @@ void f() int main() { - auto fut = std::async(f) // as above + auto fut = std::async(f); // as above if (fut.wait_for(0s) == // if task is std::future_status::deferred) // deferred... From 710f49626a554ce65d92d54ee70c7fe059f1614b Mon Sep 17 00:00:00 2001 From: ATTY Lionel Date: Tue, 10 May 2016 15:39:36 +0200 Subject: [PATCH 07/13] =?UTF-8?q?Item34:=20Semble=20manquer=20du=20code=20?= =?UTF-8?q?pour=20cet=20item.=20Par=20exemple=20la=20fonction=20setAlarm?= =?UTF-8?q?=20ne=20semble=20=C3=AAtre=20d=C3=A9finie=20nulle=20part=20....?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Item34_Prefer_lambdas_to_std_bind/CMakeLists.txt | 1 + Item34_Prefer_lambdas_to_std_bind/alarm.h | 2 ++ Item34_Prefer_lambdas_to_std_bind/alarm_with_std_bind_cpp11.cpp | 1 + .../alarm_with_std_bind_incorrect.cpp | 1 + 4 files changed, 5 insertions(+) diff --git a/Item34_Prefer_lambdas_to_std_bind/CMakeLists.txt b/Item34_Prefer_lambdas_to_std_bind/CMakeLists.txt index ed6b7f7..6bb27fb 100644 --- a/Item34_Prefer_lambdas_to_std_bind/CMakeLists.txt +++ b/Item34_Prefer_lambdas_to_std_bind/CMakeLists.txt @@ -1,3 +1,4 @@ +set_source_files_properties(alarm_with_lambda_cpp11.cpp PROPERTIES COMPILE_FLAGS "-std=gnu++14 -std=c++14") add_executable(alarm_with_lambda_cpp11 alarm_with_lambda_cpp11.cpp) #set_source_files_properties(alarm_with_lambda_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") diff --git a/Item34_Prefer_lambdas_to_std_bind/alarm.h b/Item34_Prefer_lambdas_to_std_bind/alarm.h index 899b772..cb4f3fc 100644 --- a/Item34_Prefer_lambdas_to_std_bind/alarm.h +++ b/Item34_Prefer_lambdas_to_std_bind/alarm.h @@ -1,6 +1,8 @@ #ifndef ALARM_H #define ALARM_H +#include + // typedef for a point in time (see Item 9 for syntax) using Time = std::chrono::steady_clock::time_point; diff --git a/Item34_Prefer_lambdas_to_std_bind/alarm_with_std_bind_cpp11.cpp b/Item34_Prefer_lambdas_to_std_bind/alarm_with_std_bind_cpp11.cpp index 19177e1..6b432e6 100644 --- a/Item34_Prefer_lambdas_to_std_bind/alarm_with_std_bind_cpp11.cpp +++ b/Item34_Prefer_lambdas_to_std_bind/alarm_with_std_bind_cpp11.cpp @@ -1,4 +1,5 @@ #include "alarm.h" +#include using namespace std::chrono; // as above using namespace std::placeholders; diff --git a/Item34_Prefer_lambdas_to_std_bind/alarm_with_std_bind_incorrect.cpp b/Item34_Prefer_lambdas_to_std_bind/alarm_with_std_bind_incorrect.cpp index 01505b7..4fbe016 100644 --- a/Item34_Prefer_lambdas_to_std_bind/alarm_with_std_bind_incorrect.cpp +++ b/Item34_Prefer_lambdas_to_std_bind/alarm_with_std_bind_incorrect.cpp @@ -1,4 +1,5 @@ #include "alarm.h" +#include using namespace std::chrono; // as above using namespace std::literals; From af8864fcbdb7a69ef5a87b0c4fea8c0c5e2782ca Mon Sep 17 00:00:00 2001 From: ATTY Lionel Date: Tue, 10 May 2016 15:59:02 +0200 Subject: [PATCH 08/13] =?UTF-8?q?Items:=208=2016=2021=2022=2023=2027=2031?= =?UTF-8?q?=2035=20Fix=20et=20ajout=20si=20possible=20de=20sous=20items.?= =?UTF-8?q?=20Certains=20codes=20ou=20bouts=20de=20scripts=20ne=20sont=20p?= =?UTF-8?q?as=20complets,=20du=20coup=20des=20fois=20il=20n'a=20pu=20inclu?= =?UTF-8?q?re=20les=20examples=20compl=C3=A8tements.=20Parfois=20c'est=20j?= =?UTF-8?q?uste=20des=20probl=C3=A8mes=20de=20CMake=20et/ou=20des=20erreur?= =?UTF-8?q?s=20d'innattentions=20dans=20les=20sources?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Item08_Prefer_nullptr_to_0_and_NULL/CMakeLists.txt | 5 +++-- .../CMakeLists.txt | 2 +- .../CMakeLists.txt | 4 ++-- .../limitations_of_make_functions.cpp | 4 ++-- .../reasons_for_preferring_make_functions.cpp | 2 +- .../CMakeLists.txt | 4 ++++ .../pimpl_unique_ptr/CMakeLists.txt | 2 +- .../CMakeLists.txt | 1 - .../CMakeLists.txt | 4 ---- Item31_Avoid_default_capture_modes/CMakeLists.txt | 1 - .../CMakeLists.txt | 11 ++++++++--- 11 files changed, 22 insertions(+), 18 deletions(-) diff --git a/Item08_Prefer_nullptr_to_0_and_NULL/CMakeLists.txt b/Item08_Prefer_nullptr_to_0_and_NULL/CMakeLists.txt index c998884..a78b9f0 100644 --- a/Item08_Prefer_nullptr_to_0_and_NULL/CMakeLists.txt +++ b/Item08_Prefer_nullptr_to_0_and_NULL/CMakeLists.txt @@ -3,7 +3,8 @@ add_executable(code_clarity code_clarity.cpp) add_executable(template_example_flat template_example_flat.cpp) # TODO: compile this as C++11 -# add_executable(template_example_templatized template_example_templatized.cpp) +add_executable(template_example_templatized template_example_templatized.cpp) # TODO: compile this as C++14 -#add_executable(template_example_templatized_cpp14 template_example_templatized_cpp14.cpp) +set_source_files_properties(template_example_templatized_cpp14.cpp PROPERTIES COMPILE_FLAGS -std=c++14) +add_executable(template_example_templatized_cpp14 template_example_templatized_cpp14.cpp) diff --git a/Item16_Make_const_member_functions_thread-safe/CMakeLists.txt b/Item16_Make_const_member_functions_thread-safe/CMakeLists.txt index 2b75571..a0f8cad 100644 --- a/Item16_Make_const_member_functions_thread-safe/CMakeLists.txt +++ b/Item16_Make_const_member_functions_thread-safe/CMakeLists.txt @@ -5,6 +5,6 @@ add_executable(expensive_int expensive_int.cpp) add_executable(undefined_behavior undefined_behavior.cpp) # pas très propre, faudrait une version avec cmake ... -target_link_libraries (undefined_behavior pthread) +target_link_libraries(undefined_behavior pthread) #add_library(roots Polynomial.cpp) diff --git a/Item21_Prefer_std_make_unique_and_std_make_shared_to_direct_use_of_new/CMakeLists.txt b/Item21_Prefer_std_make_unique_and_std_make_shared_to_direct_use_of_new/CMakeLists.txt index e2c39eb..ccb5b0f 100644 --- a/Item21_Prefer_std_make_unique_and_std_make_shared_to_direct_use_of_new/CMakeLists.txt +++ b/Item21_Prefer_std_make_unique_and_std_make_shared_to_direct_use_of_new/CMakeLists.txt @@ -1,5 +1,5 @@ set_source_files_properties(reasons_for_preferring_make_functions.cpp PROPERTIES COMPILE_FLAGS -std=c++14) set_source_files_properties(limitations_of_make_functions.cpp PROPERTIES COMPILE_FLAGS -std=c++14) -#add_executable(reasons_for_preferring_make_functions reasons_for_preferring_make_functions.cpp) -#add_executable(limitations_of_make_functions limitations_of_make_functions.cpp) +add_executable(reasons_for_preferring_make_functions reasons_for_preferring_make_functions.cpp) +add_executable(limitations_of_make_functions limitations_of_make_functions.cpp) diff --git a/Item21_Prefer_std_make_unique_and_std_make_shared_to_direct_use_of_new/limitations_of_make_functions.cpp b/Item21_Prefer_std_make_unique_and_std_make_shared_to_direct_use_of_new/limitations_of_make_functions.cpp index 87d667c..fce9820 100644 --- a/Item21_Prefer_std_make_unique_and_std_make_shared_to_direct_use_of_new/limitations_of_make_functions.cpp +++ b/Item21_Prefer_std_make_unique_and_std_make_shared_to_direct_use_of_new/limitations_of_make_functions.cpp @@ -44,7 +44,7 @@ int main() std::unique_ptr upw(new Widget(), widgetDeleter); - std::shared_ptr spw(new Widget(), widgetDeleter); +// std::shared_ptr spw(new Widget(), widgetDeleter); // Limitation 2: within the make function, the perfect forwarding code uses @@ -82,7 +82,7 @@ int main() // final std::weak_ptr to object destroyed here; // memory for control block and object is released - std::shared_ptr pBigObj(new ReallyBigType); + std::shared_ptr pBigObj_2(new ReallyBigType); // create very large // object via new diff --git a/Item21_Prefer_std_make_unique_and_std_make_shared_to_direct_use_of_new/reasons_for_preferring_make_functions.cpp b/Item21_Prefer_std_make_unique_and_std_make_shared_to_direct_use_of_new/reasons_for_preferring_make_functions.cpp index b93a314..c555892 100644 --- a/Item21_Prefer_std_make_unique_and_std_make_shared_to_direct_use_of_new/reasons_for_preferring_make_functions.cpp +++ b/Item21_Prefer_std_make_unique_and_std_make_shared_to_direct_use_of_new/reasons_for_preferring_make_functions.cpp @@ -50,7 +50,7 @@ int main() // leak! processWidget(std::make_shared(), // no potential - computePriority(); // resource leak + computePriority()); // resource leak // Reason 3: a special feature of make_shared is improved efficiency. diff --git a/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/CMakeLists.txt b/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/CMakeLists.txt index d1bc764..8fdc688 100644 --- a/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/CMakeLists.txt +++ b/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/CMakeLists.txt @@ -1,4 +1,8 @@ #add_subdirectory(no_pimpl) + add_subdirectory(pimpl_raw_ptr) + #TODO: fix linker error!!! add_subdirectory(pimpl_unique_ptr) +add_subdirectory(pimpl_unique_ptr) + add_subdirectory(pimpl_shared_ptr) diff --git a/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/pimpl_unique_ptr/CMakeLists.txt b/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/pimpl_unique_ptr/CMakeLists.txt index 8ca8d1f..7fb6d8d 100644 --- a/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/pimpl_unique_ptr/CMakeLists.txt +++ b/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/pimpl_unique_ptr/CMakeLists.txt @@ -1,6 +1,6 @@ include_directories(../) -set_source_files_properties(widget.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") +set_source_files_properties(widget.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") add_library(widget_pimpl_unique_ptr widget.cpp) diff --git a/Item23_Understand_std_move_and_std_forward/CMakeLists.txt b/Item23_Understand_std_move_and_std_forward/CMakeLists.txt index f63785d..dda3faa 100644 --- a/Item23_Understand_std_move_and_std_forward/CMakeLists.txt +++ b/Item23_Understand_std_move_and_std_forward/CMakeLists.txt @@ -1,4 +1,3 @@ -#set_source_files_properties(std_move_in_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") set_source_files_properties(std_move_in_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") add_executable(typical_use_of_std_forward diff --git a/Item27_Familiarize_yourself_with_alternatives_to_overloading_on_universal_references/CMakeLists.txt b/Item27_Familiarize_yourself_with_alternatives_to_overloading_on_universal_references/CMakeLists.txt index 9591586..bced506 100644 --- a/Item27_Familiarize_yourself_with_alternatives_to_overloading_on_universal_references/CMakeLists.txt +++ b/Item27_Familiarize_yourself_with_alternatives_to_overloading_on_universal_references/CMakeLists.txt @@ -1,7 +1,3 @@ -#set_source_files_properties(constraining_templates02_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -#set_source_files_properties(constraining_templates03_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") -#set_source_files_properties(constraining_templates04_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") - set_source_files_properties(constraining_templates02_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") set_source_files_properties(constraining_templates03_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") set_source_files_properties(constraining_templates04_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") diff --git a/Item31_Avoid_default_capture_modes/CMakeLists.txt b/Item31_Avoid_default_capture_modes/CMakeLists.txt index e53842d..136d64b 100644 --- a/Item31_Avoid_default_capture_modes/CMakeLists.txt +++ b/Item31_Avoid_default_capture_modes/CMakeLists.txt @@ -1,4 +1,3 @@ -#set_source_files_properties(by_reference_capture.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") set_source_files_properties(by_reference_capture.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") set_source_files_properties(Widget.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") diff --git a/Item35_Prefer_task-based_programming_to_thread-based/CMakeLists.txt b/Item35_Prefer_task-based_programming_to_thread-based/CMakeLists.txt index 782ef5c..740e14b 100644 --- a/Item35_Prefer_task-based_programming_to_thread-based/CMakeLists.txt +++ b/Item35_Prefer_task-based_programming_to_thread-based/CMakeLists.txt @@ -1,3 +1,8 @@ -#add_executable(software_threads software_threads.cpp) -#add_executable(task_based_approach task_based_approach.cpp) -#add_executable(thread_based_approach thread_based_approach.cpp) +add_executable(software_threads software_threads.cpp) +target_link_libraries(software_threads pthread) + +add_executable(task_based_approach task_based_approach.cpp) +target_link_libraries(task_based_approach pthread) + +add_executable(thread_based_approach thread_based_approach.cpp) +target_link_libraries(thread_based_approach pthread) From c6a9032de8de21ef471f6df8ce50e2843bb12b58 Mon Sep 17 00:00:00 2001 From: ATTY Lionel Date: Tue, 10 May 2016 16:13:31 +0200 Subject: [PATCH 09/13] Fix pour ajouter 'proprement' une gestion de la lib pthread --- CMakeLists.txt | 2 +- .../CMakeLists.txt | 5 ++--- .../CMakeLists.txt | 8 +++++--- .../CMakeLists.txt | 18 ++++++++++-------- .../CMakeLists.txt | 6 ++++-- .../CMakeLists.txt | 5 +++-- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d5ba95e..5a5f264 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 2.6) -project(Effective_Modern_C++ CXX C) +project(Effective_Modern_C++ C CXX) # Uncomment this to use clang++ to compile. #SET (CMAKE_CXX_COMPILER "/usr/bin/clang++-3.5") diff --git a/Item16_Make_const_member_functions_thread-safe/CMakeLists.txt b/Item16_Make_const_member_functions_thread-safe/CMakeLists.txt index a0f8cad..c661e57 100644 --- a/Item16_Make_const_member_functions_thread-safe/CMakeLists.txt +++ b/Item16_Make_const_member_functions_thread-safe/CMakeLists.txt @@ -3,8 +3,7 @@ add_executable(expensive_int expensive_int.cpp) add_executable(undefined_behavior undefined_behavior.cpp) - -# pas très propre, faudrait une version avec cmake ... -target_link_libraries(undefined_behavior pthread) +FIND_PACKAGE ( Threads REQUIRED ) +TARGET_LINK_LIBRARIES ( undefined_behavior ${CMAKE_THREAD_LIBS_INIT} ) #add_library(roots Polynomial.cpp) diff --git a/Item35_Prefer_task-based_programming_to_thread-based/CMakeLists.txt b/Item35_Prefer_task-based_programming_to_thread-based/CMakeLists.txt index 740e14b..667749a 100644 --- a/Item35_Prefer_task-based_programming_to_thread-based/CMakeLists.txt +++ b/Item35_Prefer_task-based_programming_to_thread-based/CMakeLists.txt @@ -1,8 +1,10 @@ +FIND_PACKAGE ( Threads REQUIRED ) + add_executable(software_threads software_threads.cpp) -target_link_libraries(software_threads pthread) +TARGET_LINK_LIBRARIES ( software_threads ${CMAKE_THREAD_LIBS_INIT} ) add_executable(task_based_approach task_based_approach.cpp) -target_link_libraries(task_based_approach pthread) +TARGET_LINK_LIBRARIES ( task_based_approach ${CMAKE_THREAD_LIBS_INIT} ) add_executable(thread_based_approach thread_based_approach.cpp) -target_link_libraries(thread_based_approach pthread) +TARGET_LINK_LIBRARIES ( thread_based_approach ${CMAKE_THREAD_LIBS_INIT} ) diff --git a/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/CMakeLists.txt b/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/CMakeLists.txt index 6efa6a5..cbdde0b 100644 --- a/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/CMakeLists.txt +++ b/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/CMakeLists.txt @@ -1,30 +1,32 @@ +FIND_PACKAGE ( Threads REQUIRED ) + add_executable(default_launch_policy default_launch_policy.cpp) # pas très propre, faudrait une version avec cmake ... -target_link_libraries (default_launch_policy pthread) +TARGET_LINK_LIBRARIES ( default_launch_policy ${CMAKE_THREAD_LIBS_INIT} ) add_executable(guaranteeing_truly_asynchronous_execution guaranteeing_truly_asynchronous_execution.cpp) # pas très propre, faudrait une version avec cmake ... -target_link_libraries(guaranteeing_truly_asynchronous_execution pthread) +TARGET_LINK_LIBRARIES ( guaranteeing_truly_asynchronous_execution ${CMAKE_THREAD_LIBS_INIT} ) add_executable(interesting_implications interesting_implications.cpp) # pas très propre, faudrait une version avec cmake ... -target_link_libraries(interesting_implications pthread) +TARGET_LINK_LIBRARIES ( interesting_implications ${CMAKE_THREAD_LIBS_INIT} ) add_executable(really_async_cpp11 really_async_cpp11.cpp) -target_link_libraries(really_async_cpp11 pthread) +TARGET_LINK_LIBRARIES ( really_async_cpp11 ${CMAKE_THREAD_LIBS_INIT} ) set_source_files_properties(really_async_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") add_executable(really_async_cpp14 really_async_cpp14.cpp) -target_link_libraries(really_async_cpp14 pthread) +TARGET_LINK_LIBRARIES ( really_async_cpp14 ${CMAKE_THREAD_LIBS_INIT} ) add_executable(thread_local_storage thread_local_storage.cpp) -target_link_libraries(thread_local_storage pthread) +TARGET_LINK_LIBRARIES ( thread_local_storage ${CMAKE_THREAD_LIBS_INIT} ) # url: http://stackoverflow.com/questions/35856969/chrono-literals-is-not-a-namespace-name set_source_files_properties(wait-based_loops.cpp PROPERTIES COMPILE_FLAGS "-std=gnu++14 -std=c++14") add_executable(wait-based_loops wait-based_loops.cpp) -target_link_libraries(wait-based_loops pthread) +TARGET_LINK_LIBRARIES ( wait-based_loops ${CMAKE_THREAD_LIBS_INIT} ) set_source_files_properties(wait-based_loops_fixed.cpp PROPERTIES COMPILE_FLAGS "-std=gnu++14 -std=c++14") add_executable(wait-based_loops_fixed wait-based_loops_fixed.cpp) -target_link_libraries(wait-based_loops_fixed pthread) +TARGET_LINK_LIBRARIES ( wait-based_loops_fixed ${CMAKE_THREAD_LIBS_INIT} ) diff --git a/Item37_Make_std_threads_unjoinable_on_all_paths/CMakeLists.txt b/Item37_Make_std_threads_unjoinable_on_all_paths/CMakeLists.txt index 471e330..bfd243a 100644 --- a/Item37_Make_std_threads_unjoinable_on_all_paths/CMakeLists.txt +++ b/Item37_Make_std_threads_unjoinable_on_all_paths/CMakeLists.txt @@ -1,5 +1,7 @@ +FIND_PACKAGE ( Threads REQUIRED ) + add_executable(example1 example1.cpp) -target_link_libraries(example1 pthread) +TARGET_LINK_LIBRARIES ( example1 ${CMAKE_THREAD_LIBS_INIT} ) add_executable(example2 example2.cpp) -target_link_libraries(example2 pthread) +TARGET_LINK_LIBRARIES ( example2 ${CMAKE_THREAD_LIBS_INIT} ) diff --git a/Item38_Be_aware_of_varying_thread_handle_destructor_behavior/CMakeLists.txt b/Item38_Be_aware_of_varying_thread_handle_destructor_behavior/CMakeLists.txt index f2d1b90..2357ded 100644 --- a/Item38_Be_aware_of_varying_thread_handle_destructor_behavior/CMakeLists.txt +++ b/Item38_Be_aware_of_varying_thread_handle_destructor_behavior/CMakeLists.txt @@ -1,7 +1,8 @@ # TODO: improve this CMakeLists.txt file. +FIND_PACKAGE ( Threads REQUIRED ) add_library(item38_example1 example1.cpp) -target_link_libraries(item38_example1 pthread) +TARGET_LINK_LIBRARIES ( item38_example1 ${CMAKE_THREAD_LIBS_INIT} ) add_executable(item38_example2 example2.cpp) -target_link_libraries(item38_example2 pthread) +TARGET_LINK_LIBRARIES ( item38_example2 ${CMAKE_THREAD_LIBS_INIT} ) From 75b78b870d64f2bf3c4d13463ef71ce40a867470 Mon Sep 17 00:00:00 2001 From: ATTY Lionel Date: Wed, 11 May 2016 16:58:10 +0200 Subject: [PATCH 10/13] Big refactoring ! (-> not very agile spirit :p) Add cmake tools inside a dedicated diretory 'cmake/cmake_tools.cmake'. This tool permit to add subitem(s), deal with flags for C++11 & C++14 compatibilities. Same for flags/libs needed for pthread and boost. It's a good start (i think) to unify/merge the manager of multiples builders (gcc, clang, ...). --- CMakeLists.txt | 9 +- .../CMakeLists.txt | 31 +++-- .../CMakeLists.txt | 17 ++- Item03_Understand_decltype/CMakeLists.txt | 22 ++-- .../CMakeLists.txt | 26 +++-- .../CMakeLists.txt | 8 +- .../CMakeLists.txt | 22 +++- .../CMakeLists.txt | 21 ++-- .../CMakeLists.txt | 21 ++-- .../CMakeLists.txt | 20 ++-- .../CMakeLists.txt | 15 +++ .../CMakeLists.txt | 13 ++- .../CMakeLists.txt | 23 ++-- .../CMakeLists.txt | 15 ++- .../CMakeLists.txt | 13 ++- .../CMakeLists.txt | 17 ++- .../CMakeLists.txt | 6 + .../CMakeLists.txt | 6 +- .../CMakeLists.txt | 9 +- .../CMakeLists.txt | 6 +- .../CMakeLists.txt | 10 +- .../CMakeLists.txt | 2 + .../pimpl_shared_ptr/CMakeLists.txt | 6 + .../pimpl_unique_ptr/CMakeLists.txt | 5 + .../CMakeLists.txt | 11 +- .../CMakeLists.txt | 11 +- .../CMakeLists.txt | 10 ++ .../CMakeLists.txt | 11 +- .../CMakeLists.txt | 18 ++- .../CMakeLists.txt | 16 ++- .../CMakeLists.txt | 6 +- .../CMakeLists.txt | 18 ++- .../CMakeLists.txt | 11 +- .../CMakeLists.txt | 32 ++--- .../CMakeLists.txt | 3 +- .../CMakeLists.txt | 16 +-- .../CMakeLists.txt | 46 +++----- .../CMakeLists.txt | 12 +- .../CMakeLists.txt | 20 ++-- .../example2.cpp | 2 +- cmake/cmake_tools.cmake | 110 ++++++++++++++++++ 41 files changed, 487 insertions(+), 209 deletions(-) create mode 100644 cmake/cmake_tools.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a5f264..83e32bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required(VERSION 2.6) +#project(Effective_Modern_C++ C CXX) project(Effective_Modern_C++ C CXX) # Uncomment this to use clang++ to compile. @@ -9,7 +10,13 @@ project(Effective_Modern_C++ C CXX) # compiles with any C++ compiler, so make this more portable. Also, some files # should be compiled as C++11, others as C++14. Find out how we can # differentiate. -set(CMAKE_CXX_FLAGS "-std=c++11") +#set(CMAKE_CXX_FLAGS "-std=c++11") + +FIND_PACKAGE ( Threads REQUIRED ) + +set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${PROJECT_SOURCE_DIR}/cmake") + +include(cmake_tools) add_subdirectory(Item01_Understand_template_type_deduction) add_subdirectory(Item02_Understand_auto_type_deduction) diff --git a/Item01_Understand_template_type_deduction/CMakeLists.txt b/Item01_Understand_template_type_deduction/CMakeLists.txt index 40f572e..2db2f3d 100644 --- a/Item01_Understand_template_type_deduction/CMakeLists.txt +++ b/Item01_Understand_template_type_deduction/CMakeLists.txt @@ -1,13 +1,20 @@ -add_executable(pinch_of_pseudocode pinch_of_pseudocode.cpp) -add_executable(case1_const case1_const.cpp) -add_executable(case1_non_const case1_non_const.cpp) -add_executable(case1_pointer case1_pointer.cpp) -add_executable(case2_uref case2_uref.cpp) -add_executable(case3_pass_by_value case3_pass_by_value.cpp) -add_executable(array-to-pointer_decay_rule array-to-pointer_decay_rule.cpp) -add_executable(arrays_by_value arrays_by_value.cpp) -add_executable(arrays_by_reference arrays_by_reference.cpp) -add_executable(function-to-pointer_decay_rule function-to-pointer_decay_rule.cpp) +SET(NAMES_SAMPLES + pinch_of_pseudocode + case1_const + case1_non_const + case1_pointer + case3_pass_by_value + array-to-pointer_decay_rule + arrays_by_value + arrays_by_reference + function-to-pointer_decay_rule +) +subitems_add_executables("${NAMES_SAMPLES}" "") -add_library(item01 deduce_nb_array_elements.cpp - array_and_pointer_parameter_equivalence.cpp) +subitem_add_executable(NAME case2_uref SRC case2_uref.cpp ADD_FLAG_FOR_CXX_11) + +subitem_add_library( + NAME item01 + SRC deduce_nb_array_elements.cpp array_and_pointer_parameter_equivalence.cpp + ADD_FLAG_FOR_CXX_11 +) diff --git a/Item02_Understand_auto_type_deduction/CMakeLists.txt b/Item02_Understand_auto_type_deduction/CMakeLists.txt index 0da5902..3eb1e28 100644 --- a/Item02_Understand_auto_type_deduction/CMakeLists.txt +++ b/Item02_Understand_auto_type_deduction/CMakeLists.txt @@ -1,5 +1,14 @@ -set_source_files_properties(function_return_type_deduction.cpp PROPERTIES COMPILE_FLAGS -std=c++14) +subitem_add_executable( + NAME auto_type_deduction + SRC auto_type_deduction.cpp + ADD_FLAG_FOR_CXX_11) -add_executable(auto_type_deduction auto_type_deduction.cpp) -add_executable(auto_deduction_vs_template_deduction auto_deduction_vs_template_deduction.cpp) -add_executable(function_return_type_deduction function_return_type_deduction.cpp) +subitem_add_executable( + NAME auto_deduction_vs_template_deduction + SRC auto_deduction_vs_template_deduction.cpp + ADD_FLAG_FOR_CXX_11) + +subitem_add_executable( + NAME function_return_type_deduction + SRC function_return_type_deduction.cpp + ADD_FLAG_FOR_CXX_14) diff --git a/Item03_Understand_decltype/CMakeLists.txt b/Item03_Understand_decltype/CMakeLists.txt index 7426dc5..195479f 100644 --- a/Item03_Understand_decltype/CMakeLists.txt +++ b/Item03_Understand_decltype/CMakeLists.txt @@ -1,11 +1,13 @@ -# TODO: check C++14 code! +## TODO: check C++14 code! +subitem_add_executable( + NAME decltype_for_complicated_lvalues + SRC decltype_for_complicated_lvalues.cpp +) -add_executable(decltype_for_complicated_lvalues decltype_for_complicated_lvalues.cpp) - -add_library(item02 problem.cpp -# decltype_auto_for_function_return_types_cpp14.cpp -# decltype_auto_for_normal_auto_variables_cpp14.cpp - typical_cases.cpp - string_deque.cpp -# return_statements_cpp14.cpp - ) +subitem_add_library( + NAME item02 + SRC problem.cpp typical_cases.cpp string_deque.cpp + # decltype_auto_for_function_return_types_cpp14.cpp + # return_statements_cpp14.cpp + ADD_FLAG_FOR_CXX_11 +) diff --git a/Item04_Know_how_to_view_deduced_types/CMakeLists.txt b/Item04_Know_how_to_view_deduced_types/CMakeLists.txt index a1bcfef..1a0ce10 100644 --- a/Item04_Know_how_to_view_deduced_types/CMakeLists.txt +++ b/Item04_Know_how_to_view_deduced_types/CMakeLists.txt @@ -1,9 +1,21 @@ -add_executable(runtime_output01 runtime_output01.cpp) -add_executable(runtime_output02 runtime_output02.cpp) -add_executable(boost_type_index boost_type_index.cpp) +SET(NAMES_SAMPLES + runtime_output01 + runtime_output02 +) +SET(FLAGS_FOR_SAMPLES + ADD_FLAG_FOR_CXX_11 +) +subitems_add_executables("${NAMES_SAMPLES}" "${FLAGS_FOR_SAMPLES}") -add_library(ide_editors.cpp - compiler_diagnostics.cpp) +subitem_add_executable( + NAME boost_type_index + SRC boost_type_index.cpp + ADD_FLAG_FOR_CXX_11 + USE_BOOST +) -find_package(Boost 1.56 REQUIRED) -target_link_libraries(boost_type_index ${Boost_LIBRARIES}) +subitem_add_library( + NAME ide_editors + SRC compiler_diagnostics.cpp + ADD_FLAG_FOR_CXX_11 +) diff --git a/Item05_Prefer_auto_to_explicit_type_declarations/CMakeLists.txt b/Item05_Prefer_auto_to_explicit_type_declarations/CMakeLists.txt index be33eb1..a4cf041 100644 --- a/Item05_Prefer_auto_to_explicit_type_declarations/CMakeLists.txt +++ b/Item05_Prefer_auto_to_explicit_type_declarations/CMakeLists.txt @@ -1,5 +1,7 @@ -set_source_files_properties(auto.cpp PROPERTIES COMPILE_FLAGS -std=c++14) - #TODO: wait until clang bug fixed!!! add_executable(auto auto.cpp) -add_library(simple_joys simple_joys.cpp) +subitem_add_library( + NAME simple_joys + SRC simple_joys.cpp + ADD_FLAG_FOR_CXX_11 +) diff --git a/Item06_Use_the_explicitly_typed_initializer_idiom_when_auto_deduces_undesired_types/CMakeLists.txt b/Item06_Use_the_explicitly_typed_initializer_idiom_when_auto_deduces_undesired_types/CMakeLists.txt index b5b0867..46dcc40 100644 --- a/Item06_Use_the_explicitly_typed_initializer_idiom_when_auto_deduces_undesired_types/CMakeLists.txt +++ b/Item06_Use_the_explicitly_typed_initializer_idiom_when_auto_deduces_undesired_types/CMakeLists.txt @@ -1,3 +1,19 @@ -add_executable(invisible_proxy_types invisible_proxy_types.cpp) -#add_executable(matrix_example matrix_example.cpp) -add_executable(typed_initializer_idiom typed_initializer_idiom.cpp) +# ps: exception in execution ! +# TODO: debug this sample ! +subitem_add_executable( + NAME invisible_proxy_types + SRC invisible_proxy_types.cpp + ADD_FLAG_FOR_CXX_11 +) + +subitem_add_executable( + NAME typed_initializer_idiom + SRC typed_initializer_idiom.cpp + ADD_FLAG_FOR_CXX_11 +) + +#subitem_add_executable( +# NAME matrix_example +# SRC matrix_example.cpp +# ADD_FLAG_FOR_CXX_11 +#) diff --git a/Item07_Distinguish_between()_and_{}_when_creating_objects/CMakeLists.txt b/Item07_Distinguish_between()_and_{}_when_creating_objects/CMakeLists.txt index 51a9f1f..8fb6016 100644 --- a/Item07_Distinguish_between()_and_{}_when_creating_objects/CMakeLists.txt +++ b/Item07_Distinguish_between()_and_{}_when_creating_objects/CMakeLists.txt @@ -1,7 +1,14 @@ -add_executable(constructor_overload_resolution constructor_overload_resolution.cpp) -add_executable(initialization_values initialization_values.cpp) -add_executable(initializer_lists1 initializer_lists1.cpp) -add_executable(initializer_lists2 initializer_lists2.cpp) -add_executable(initializer_lists3 initializer_lists3.cpp) -add_executable(initializer_lists4 initializer_lists4.cpp) -add_executable(parenthesis_braces_in_templates parenthesis_braces_in_templates.cpp) +SET(NAMES_SAMPLES + constructor_overload_resolution + initialization_values + initializer_lists1 + initializer_lists2 + initializer_lists3 + initializer_lists4 + parenthesis_braces_in_templates +) +SET(FLAGS_FOR_SAMPLES + ADD_FLAG_FOR_CXX_11 +) + +subitems_add_executables("${NAMES_SAMPLES}" "${FLAGS_FOR_SAMPLES}") diff --git a/Item08_Prefer_nullptr_to_0_and_NULL/CMakeLists.txt b/Item08_Prefer_nullptr_to_0_and_NULL/CMakeLists.txt index a78b9f0..d17e508 100644 --- a/Item08_Prefer_nullptr_to_0_and_NULL/CMakeLists.txt +++ b/Item08_Prefer_nullptr_to_0_and_NULL/CMakeLists.txt @@ -1,10 +1,13 @@ -add_executable(pointer_overload pointer_overload.cpp) -add_executable(code_clarity code_clarity.cpp) -add_executable(template_example_flat template_example_flat.cpp) +SET(NAMES_SAMPLES + pointer_overload + code_clarity + template_example_flat + template_example_templatized +) +subitems_add_executables("${NAMES_SAMPLES}" "ADD_FLAG_FOR_CXX_11") -# TODO: compile this as C++11 -add_executable(template_example_templatized template_example_templatized.cpp) - -# TODO: compile this as C++14 -set_source_files_properties(template_example_templatized_cpp14.cpp PROPERTIES COMPILE_FLAGS -std=c++14) -add_executable(template_example_templatized_cpp14 template_example_templatized_cpp14.cpp) +subitem_add_executable( + NAME template_example_templatized_cpp14 + SRC template_example_templatized_cpp14.cpp + ADD_FLAG_FOR_CXX_14 +) diff --git a/Item09_Prefer_alias_declarations_to_typedefs/CMakeLists.txt b/Item09_Prefer_alias_declarations_to_typedefs/CMakeLists.txt index 7644091..d4296d5 100644 --- a/Item09_Prefer_alias_declarations_to_typedefs/CMakeLists.txt +++ b/Item09_Prefer_alias_declarations_to_typedefs/CMakeLists.txt @@ -1,7 +1,13 @@ -add_library(item09 function_pointers.cpp - linked_list_synonym_with_alias_template01.cpp - linked_list_synonym_with_alias_template02.cpp - linked_list_synonym_with_typedef01.cpp - linked_list_synonym_with_typedef02.cpp - # TODO wine.cpp - ) +SET(SRC_FILES + function_pointers.cpp + linked_list_synonym_with_alias_template01.cpp + linked_list_synonym_with_alias_template02.cpp + linked_list_synonym_with_typedef01.cpp + linked_list_synonym_with_typedef02.cpp + # TODO wine.cpp +) +subitem_add_library( + NAME item09 + SRC ${SRC_FILES} + ADD_FLAG_FOR_CXX_11 +) diff --git a/Item10_Prefer_scoped_enums_to_unscoped_enums/CMakeLists.txt b/Item10_Prefer_scoped_enums_to_unscoped_enums/CMakeLists.txt index fd69711..83cd06e 100644 --- a/Item10_Prefer_scoped_enums_to_unscoped_enums/CMakeLists.txt +++ b/Item10_Prefer_scoped_enums_to_unscoped_enums/CMakeLists.txt @@ -1,3 +1,18 @@ +SET(SRC_FILES_Cxx11 + scoped_enums.cpp + semantic_travesties01.cpp + semantic_travesties02.cpp + semantic_travesties03.cpp + forward_declaring.cpp + forward_declared_enums.cpp + underlying_type02.cpp + unscoped_enums_useful01.cpp + unscoped_enums_useful02.cpp + unscoped_enums_useful03.cpp + unscoped_enums_useful04.cpp +) +add_std_cxx11_flag("${SRC_FILES_Cxx11}") + add_library(item10 unscoped_enums.cpp scoped_enums.cpp semantic_travesties01.cpp diff --git a/Item11_Prefer_deleted_functions_to_private_undefined_ones/CMakeLists.txt b/Item11_Prefer_deleted_functions_to_private_undefined_ones/CMakeLists.txt index 1e45242..d790de8 100644 --- a/Item11_Prefer_deleted_functions_to_private_undefined_ones/CMakeLists.txt +++ b/Item11_Prefer_deleted_functions_to_private_undefined_ones/CMakeLists.txt @@ -1,3 +1,10 @@ -add_executable(Item12 Item12.cpp) -add_library(pointer_example pointer_example.cpp) -add_library(Widget Widget.cpp) +subitem_add_executable( + NAME Item12 + SRC Item12.cpp + ADD_FLAG_FOR_CXX_11) + +SET(NAMES_SAMPLES + pointer_example + Widget +) +subitems_add_libraries("${NAMES_SAMPLES}" "ADD_FLAG_FOR_CXX_11") diff --git a/Item12_Declare_overriding_functions_override/CMakeLists.txt b/Item12_Declare_overriding_functions_override/CMakeLists.txt index 2faea90..d14d47f 100644 --- a/Item12_Declare_overriding_functions_override/CMakeLists.txt +++ b/Item12_Declare_overriding_functions_override/CMakeLists.txt @@ -1,9 +1,18 @@ add_executable(overriding_explained overriding_explained.cpp) -add_executable(reference_qualifiers_example reference_qualifiers_example.cpp) -add_library(typical_errors typical_errors.cpp) -add_library(typical_errors_with_override_added typical_errors_with_override_added.cpp) -add_library(typical_errors_corrected typical_errors_corrected.cpp) + +SET(NAMES_SAMPLES + reference-qualified_member_functions_use_case_problem_demonstration + reference-qualified_member_functions_use_case_problem_solution + reference_qualifiers_example +) +subitems_add_executables("${NAMES_SAMPLES}" "ADD_FLAG_FOR_CXX_11") + +SET(NAMES_SAMPLES + typical_errors + typical_errors_with_override_added + typical_errors_corrected + override_games +) +subitems_add_libraries("${NAMES_SAMPLES}" "ADD_FLAG_FOR_CXX_11") + add_library(override_legacy_code override_legacy_code.cpp) -add_library(override_games override_games.cpp) -add_executable(reference-qualified_member_functions_use_case_problem_demonstration reference-qualified_member_functions_use_case_problem_demonstration.cpp) -add_executable(reference-qualified_member_functions_use_case_problem_solution reference-qualified_member_functions_use_case_problem_solution.cpp) diff --git a/Item13_Prefer_const_iterators_to_iterators/CMakeLists.txt b/Item13_Prefer_const_iterators_to_iterators/CMakeLists.txt index da33fe1..b1918dd 100644 --- a/Item13_Prefer_const_iterators_to_iterators/CMakeLists.txt +++ b/Item13_Prefer_const_iterators_to_iterators/CMakeLists.txt @@ -1,8 +1,13 @@ add_executable(insertion_cpp98 insertion_cpp98.cpp) -# TODO: find out why this doesn't compile!!! add_executable(insertion_cpp11 insertion_cpp11.cpp) -add_executable(insertion_cpp11 insertion_cpp11.cpp) # work on gcc-4.9 +subitem_add_executable( + NAME insertion_cpp11 + SRC insertion_cpp11.cpp + ADD_FLAG_FOR_CXX_11 +) -# TODO add_executable(insertion_cpp11 insertion_cpp14.cpp) -#set_source_files_properties(insertion_cpp14.cpp PROPERTIES COMPILE_FLAGS -std=c++14) -add_executable(insertion_cpp14 insertion_cpp14.cpp) +subitem_add_executable( + NAME insertion_cpp14 + SRC insertion_cpp14.cpp + ADD_FLAG_FOR_CXX_14 +) diff --git a/Item14_Declare_functions_noexcept_if_they_wont_emit_exceptions/CMakeLists.txt b/Item14_Declare_functions_noexcept_if_they_wont_emit_exceptions/CMakeLists.txt index 35fc7cd..ee6da6f 100644 --- a/Item14_Declare_functions_noexcept_if_they_wont_emit_exceptions/CMakeLists.txt +++ b/Item14_Declare_functions_noexcept_if_they_wont_emit_exceptions/CMakeLists.txt @@ -1,4 +1,13 @@ -add_library(never_throw_exception never_throw_exception.cpp) +subitem_add_library( + NAME never_throw_exception + SRC never_throw_exception.cpp + ADD_FLAG_FOR_CXX_11 +) + add_library(example_with_move example_with_move.cpp) -add_executable(inconsistencies inconsistencies.cpp) +subitem_add_executable( + NAME inconsistencies + SRC inconsistencies.cpp + ADD_FLAG_FOR_CXX_11 +) diff --git a/Item16_Make_const_member_functions_thread-safe/CMakeLists.txt b/Item16_Make_const_member_functions_thread-safe/CMakeLists.txt index c661e57..99ef38d 100644 --- a/Item16_Make_const_member_functions_thread-safe/CMakeLists.txt +++ b/Item16_Make_const_member_functions_thread-safe/CMakeLists.txt @@ -1,9 +1,14 @@ -# TODO: complete this CMakeLists.txt +subitem_add_executable( + NAME expensive_int + SRC expensive_int.cpp + ADD_FLAG_FOR_CXX_11 +) -add_executable(expensive_int expensive_int.cpp) - -add_executable(undefined_behavior undefined_behavior.cpp) -FIND_PACKAGE ( Threads REQUIRED ) -TARGET_LINK_LIBRARIES ( undefined_behavior ${CMAKE_THREAD_LIBS_INIT} ) +subitem_add_executable( + NAME undefined_behavior + SRC undefined_behavior.cpp + ADD_FLAG_FOR_CXX_11 + USE_PTHREAD +) #add_library(roots Polynomial.cpp) diff --git a/Item17_Understand_special_member_function_generation/CMakeLists.txt b/Item17_Understand_special_member_function_generation/CMakeLists.txt index c111d52..baa8d06 100644 --- a/Item17_Understand_special_member_function_generation/CMakeLists.txt +++ b/Item17_Understand_special_member_function_generation/CMakeLists.txt @@ -1,3 +1,9 @@ +SET(SRC_FILES_Cxx11 + Widget01.cpp + Widget02.cpp +) +add_std_cxx11_flag("${SRC_FILES_Cxx11}") + add_library(itemXX Widget01.cpp Widget02.cpp Widget03.cpp diff --git a/Item18_Use_std_unique_ptr_for_exclusive-ownership_resource_management/CMakeLists.txt b/Item18_Use_std_unique_ptr_for_exclusive-ownership_resource_management/CMakeLists.txt index 7f06878..2162235 100644 --- a/Item18_Use_std_unique_ptr_for_exclusive-ownership_resource_management/CMakeLists.txt +++ b/Item18_Use_std_unique_ptr_for_exclusive-ownership_resource_management/CMakeLists.txt @@ -1,2 +1,6 @@ -#add_library(investments_cpp11 investments_cpp11.cpp) +#subitem_add_library( +# NAME investments_cpp11 +# SRC investments_cpp11.cpp +# ADD_FLAG_FOR_CXX_11 +#) #add_library(investments_cpp14 investments_cpp14.cpp) diff --git a/Item19_Use_std_shared_ptr_for_shared-ownership_resource_management/CMakeLists.txt b/Item19_Use_std_shared_ptr_for_shared-ownership_resource_management/CMakeLists.txt index 9f92139..bf17dbf 100644 --- a/Item19_Use_std_shared_ptr_for_shared-ownership_resource_management/CMakeLists.txt +++ b/Item19_Use_std_shared_ptr_for_shared-ownership_resource_management/CMakeLists.txt @@ -1,3 +1,6 @@ -add_library(custom_deleters custom_deleters.cpp) -add_library(multiple_control_blocks1 multiple_control_blocks1.cpp) -add_library(multiple_control_blocks2 multiple_control_blocks2.cpp) +SET(SAMPLES_NAMES + custom_deleters + multiple_control_blocks1 + multiple_control_blocks2 +) +subitems_add_libraries("${SAMPLES_NAMES}" "ADD_FLAG_FOR_CXX_11") diff --git a/Item20_Use_std_weak_ptr_for_std_shared_ptr-like_pointers_that_can_dangle/CMakeLists.txt b/Item20_Use_std_weak_ptr_for_std_shared_ptr-like_pointers_that_can_dangle/CMakeLists.txt index 2486727..231a4b8 100644 --- a/Item20_Use_std_weak_ptr_for_std_shared_ptr-like_pointers_that_can_dangle/CMakeLists.txt +++ b/Item20_Use_std_weak_ptr_for_std_shared_ptr-like_pointers_that_can_dangle/CMakeLists.txt @@ -1 +1,5 @@ -add_executable(creation creation.cpp) +subitem_add_executable( + NAME creation + SRC creation + ADD_FLAG_FOR_CXX_11 +) diff --git a/Item21_Prefer_std_make_unique_and_std_make_shared_to_direct_use_of_new/CMakeLists.txt b/Item21_Prefer_std_make_unique_and_std_make_shared_to_direct_use_of_new/CMakeLists.txt index ccb5b0f..1da8880 100644 --- a/Item21_Prefer_std_make_unique_and_std_make_shared_to_direct_use_of_new/CMakeLists.txt +++ b/Item21_Prefer_std_make_unique_and_std_make_shared_to_direct_use_of_new/CMakeLists.txt @@ -1,5 +1,5 @@ -set_source_files_properties(reasons_for_preferring_make_functions.cpp PROPERTIES COMPILE_FLAGS -std=c++14) -set_source_files_properties(limitations_of_make_functions.cpp PROPERTIES COMPILE_FLAGS -std=c++14) - -add_executable(reasons_for_preferring_make_functions reasons_for_preferring_make_functions.cpp) -add_executable(limitations_of_make_functions limitations_of_make_functions.cpp) +SET(SAMPLES_NAMES + reasons_for_preferring_make_functions + limitations_of_make_functions +) +subitems_add_executables("${SAMPLES_NAMES}" "ADD_FLAG_FOR_CXX_14") diff --git a/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/CMakeLists.txt b/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/CMakeLists.txt index 8fdc688..f238ae0 100644 --- a/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/CMakeLists.txt +++ b/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/CMakeLists.txt @@ -1,3 +1,5 @@ +# TODO: need to be clean ! + #add_subdirectory(no_pimpl) add_subdirectory(pimpl_raw_ptr) diff --git a/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/pimpl_shared_ptr/CMakeLists.txt b/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/pimpl_shared_ptr/CMakeLists.txt index 5e2e32d..ab27dd7 100644 --- a/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/pimpl_shared_ptr/CMakeLists.txt +++ b/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/pimpl_shared_ptr/CMakeLists.txt @@ -1,3 +1,9 @@ +SET(SRC_FILES_Cxx11 + widget.cpp + client.cpp +) +add_std_cxx11_flag("${SRC_FILES_Cxx11}") + include_directories(../) add_library(widget_pimpl_shared_ptr widget.cpp) diff --git a/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/pimpl_unique_ptr/CMakeLists.txt b/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/pimpl_unique_ptr/CMakeLists.txt index 7fb6d8d..b156b58 100644 --- a/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/pimpl_unique_ptr/CMakeLists.txt +++ b/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/pimpl_unique_ptr/CMakeLists.txt @@ -1,3 +1,8 @@ +SET(SRC_FILES_Cxx11 + client.cpp +) +add_std_cxx11_flag("${SRC_FILES_Cxx11}") + include_directories(../) set_source_files_properties(widget.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") diff --git a/Item23_Understand_std_move_and_std_forward/CMakeLists.txt b/Item23_Understand_std_move_and_std_forward/CMakeLists.txt index dda3faa..9d7216e 100644 --- a/Item23_Understand_std_move_and_std_forward/CMakeLists.txt +++ b/Item23_Understand_std_move_and_std_forward/CMakeLists.txt @@ -1,4 +1,13 @@ -set_source_files_properties(std_move_in_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") +SET(SRC_FILES_Cxx11 + std_move_in_cpp11.cpp + annotation.cpp + move_constructor_with_move.cpp + move_constructor_with_forward.cpp + typical_use_of_std_forward.cpp +) +add_std_cxx11_flag("${SRC_FILES_Cxx11}") + +add_std_cxx14_flag("std_move_in_cpp14.cpp") add_executable(typical_use_of_std_forward typical_use_of_std_forward.cpp) diff --git a/Item24_Distinguish_universal_references_from_rvalue_references/CMakeLists.txt b/Item24_Distinguish_universal_references_from_rvalue_references/CMakeLists.txt index e792c4d..536d0ec 100644 --- a/Item24_Distinguish_universal_references_from_rvalue_references/CMakeLists.txt +++ b/Item24_Distinguish_universal_references_from_rvalue_references/CMakeLists.txt @@ -1,7 +1,16 @@ +SET(SRC_FILES_Cxx11 + rrefs_examples.cpp + urefs_contexts.cpp + no_type_deduction.cpp + urefs_form.cpp + urefs_initialization.cpp +) +add_std_cxx11_flag("${SRC_FILES_Cxx11}") + # TODO: use Boost TypeIndex instead. include_directories(../../3rd_party) -set_source_files_properties(record_time.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") +add_std_cxx14_flag("record_time.cpp") add_executable(urefs_initialization urefs_initialization.cpp) add_executable(urefs_form urefs_form.cpp) diff --git a/Item25_Use_std_move_on_rvalue_references_std_forward_on_universal_references/CMakeLists.txt b/Item25_Use_std_move_on_rvalue_references_std_forward_on_universal_references/CMakeLists.txt index 1141c01..3278ee2 100644 --- a/Item25_Use_std_move_on_rvalue_references_std_forward_on_universal_references/CMakeLists.txt +++ b/Item25_Use_std_move_on_rvalue_references_std_forward_on_universal_references/CMakeLists.txt @@ -1,3 +1,13 @@ +SET(SRC_FILES_Cxx11 + dont_use_move_with_urefs.cpp + dont_use_move_with_urefs_solution.cpp + rrefs_are_moveable.cpp + urefs_maybe_moveable.cpp + reduce_and_copy.cpp + matrix.cpp +) +add_std_cxx11_flag("${SRC_FILES_Cxx11}") + add_executable(dont_use_move_with_urefs dont_use_move_with_urefs.cpp) add_executable(dont_use_move_with_urefs_solution dont_use_move_with_urefs_solution.cpp) diff --git a/Item26_Avoid_overloading_on_universal_references/CMakeLists.txt b/Item26_Avoid_overloading_on_universal_references/CMakeLists.txt index f60e8d0..32161e1 100644 --- a/Item26_Avoid_overloading_on_universal_references/CMakeLists.txt +++ b/Item26_Avoid_overloading_on_universal_references/CMakeLists.txt @@ -1,4 +1,7 @@ -add_executable(logAndAdd_inefficient logAndAdd_inefficient.cpp) -add_executable(logAndAdd_with_uref logAndAdd_with_uref.cpp) -add_executable(logAndAdd_with_uref_overloaded logAndAdd_with_uref_overloaded.cpp) -add_executable(Person Person.cpp) +SET(SAMPLES_NAMES + Person + logAndAdd_inefficient + logAndAdd_with_uref + logAndAdd_with_uref_overloaded +) +subitems_add_executables("${SAMPLES_NAMES}" "ADD_FLAG_FOR_CXX_11") diff --git a/Item27_Familiarize_yourself_with_alternatives_to_overloading_on_universal_references/CMakeLists.txt b/Item27_Familiarize_yourself_with_alternatives_to_overloading_on_universal_references/CMakeLists.txt index bced506..5f29cc3 100644 --- a/Item27_Familiarize_yourself_with_alternatives_to_overloading_on_universal_references/CMakeLists.txt +++ b/Item27_Familiarize_yourself_with_alternatives_to_overloading_on_universal_references/CMakeLists.txt @@ -1,6 +1,18 @@ -set_source_files_properties(constraining_templates02_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") -set_source_files_properties(constraining_templates03_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") -set_source_files_properties(constraining_templates04_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") +SET(SRC_FILES_Cxx11 + alternative_pass_by_value.cpp + tag_dispatch01.cpp + tag_dispatch02.cpp + constraining_templates01.cpp + constraining_templates02_cpp11.cpp +) +add_std_cxx11_flag("${SRC_FILES_Cxx11}") + +SET(SRC_FILES_Cxx14 + constraining_templates02_cpp14.cpp + constraining_templates03_cpp14.cpp + constraining_templates04_cpp14.cpp +) +add_std_cxx14_flag("${SRC_FILES_Cxx14}") add_library(alternatives_to_uref_overloading alternative_pass_by_value.cpp tag_dispatch01.cpp diff --git a/Item28_Understand_reference_collapsing/CMakeLists.txt b/Item28_Understand_reference_collapsing/CMakeLists.txt index e632f42..658ea41 100644 --- a/Item28_Understand_reference_collapsing/CMakeLists.txt +++ b/Item28_Understand_reference_collapsing/CMakeLists.txt @@ -1,11 +1,9 @@ -#include_directories(../../utils) - -add_executable(refs_to_refs1 - refs_to_refs.cpp) -#target_link_libraries(refs_to_refs effc++11) +SET(SAMPLES_NAMES + reference_collapsing_contexts01 + reference_collapsing_contexts02 +) +subitems_add_executables("${SAMPLES_NAMES}" "ADD_FLAG_FOR_CXX_11") -add_executable(reference_collapsing_contexts01 - reference_collapsing_contexts01.cpp) +#include_directories(../../utils) -add_executable(reference_collapsing_contexts02 - reference_collapsing_contexts02.cpp) +add_executable(refs_to_refs1 refs_to_refs.cpp) diff --git a/Item29_Assume_that_move_operations_are_not_present_not_cheap_and_not_used/CMakeLists.txt b/Item29_Assume_that_move_operations_are_not_present_not_cheap_and_not_used/CMakeLists.txt index 9badcc9..5779627 100644 --- a/Item29_Assume_that_move_operations_are_not_present_not_cheap_and_not_used/CMakeLists.txt +++ b/Item29_Assume_that_move_operations_are_not_present_not_cheap_and_not_used/CMakeLists.txt @@ -1,2 +1,4 @@ -add_executable(moving_containers - moving_containers.cpp) +SET(SAMPLES_NAMES + moving_containers +) +subitems_add_executables("${SAMPLES_NAMES}" "ADD_FLAG_FOR_CXX_11") diff --git a/Item30_Familiarize_yourself_with_perfect_forwarding_failure_cases/CMakeLists.txt b/Item30_Familiarize_yourself_with_perfect_forwarding_failure_cases/CMakeLists.txt index 8cc36ec..e1d357f 100644 --- a/Item30_Familiarize_yourself_with_perfect_forwarding_failure_cases/CMakeLists.txt +++ b/Item30_Familiarize_yourself_with_perfect_forwarding_failure_cases/CMakeLists.txt @@ -1,10 +1,8 @@ -add_executable(braced_initializers - braced_initializers.cpp) -add_executable(null_pointers - null_pointers.cpp) -add_executable(declaration-only_integral_static_const_data_members - declaration-only_integral_static_const_data_members.cpp) -add_executable(overloaded_function_names_and_template_names - overloaded_function_names_and_template_names.cpp) -add_executable(bitfields - bitfields.cpp) +SET(SAMPLES_NAMES + braced_initializers + null_pointers + declaration-only_integral_static_const_data_members + overloaded_function_names_and_template_names + bitfields +) +subitems_add_executables("${SAMPLES_NAMES}" "ADD_FLAG_FOR_CXX_11") diff --git a/Item31_Avoid_default_capture_modes/CMakeLists.txt b/Item31_Avoid_default_capture_modes/CMakeLists.txt index 136d64b..ca8e4f2 100644 --- a/Item31_Avoid_default_capture_modes/CMakeLists.txt +++ b/Item31_Avoid_default_capture_modes/CMakeLists.txt @@ -1,5 +1,6 @@ -set_source_files_properties(by_reference_capture.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") -set_source_files_properties(Widget.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") - -add_executable(by_reference_capture - Widget.cpp by_reference_capture.cpp) +SET(SRC_FILES_Cxx14 + by_reference_capture.cpp + Widget.cpp +) +add_std_cxx14_flag("${SRC_FILES_Cxx14}") +add_executable(by_reference_capture ${SRC_FILES_Cxx14}) diff --git a/Item32_Use_init_capture_to_move_objects_into_closures/CMakeLists.txt b/Item32_Use_init_capture_to_move_objects_into_closures/CMakeLists.txt index b8679da..5092f34 100644 --- a/Item32_Use_init_capture_to_move_objects_into_closures/CMakeLists.txt +++ b/Item32_Use_init_capture_to_move_objects_into_closures/CMakeLists.txt @@ -1,20 +1,12 @@ -set_source_files_properties(init_capture_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") -add_executable(init_capture_cpp14 - init_capture_cpp14.cpp) - -set_source_files_properties(init_capture_cpp11.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") -add_executable(init_capture_cpp11 - init_capture_cpp11.cpp - Widget.cpp) - -set_source_files_properties(move_capture1_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") -add_executable(move_capture1_cpp14 - move_capture1_cpp14.cpp) - -add_executable(move_capture1_cpp11 - move_capture1_cpp11.cpp) - -set_source_files_properties(move_capture2.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") -add_executable(move_capture2 - move_capture2.cpp) - +SET(SAMPLES_NAMES + move_capture1_cpp11 +) +subitems_add_executables("${SAMPLES_NAMES}" "ADD_FLAG_FOR_CXX_11") + +SET(SAMPLES_NAMES + init_capture_cpp14 + init_capture_cpp11 + move_capture1_cpp14 + move_capture2 +) +subitems_add_executables("${SAMPLES_NAMES}" "ADD_FLAG_FOR_CXX_14") diff --git a/Item33_Use_decltype_on_autorr_parameters_to_std_forward_them/CMakeLists.txt b/Item33_Use_decltype_on_autorr_parameters_to_std_forward_them/CMakeLists.txt index a4f588b..4cf14e0 100644 --- a/Item33_Use_decltype_on_autorr_parameters_to_std_forward_them/CMakeLists.txt +++ b/Item33_Use_decltype_on_autorr_parameters_to_std_forward_them/CMakeLists.txt @@ -1,2 +1 @@ -set_source_files_properties(item35.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") -add_executable(item35 item35.cpp) +subitems_add_executables("item35" "ADD_FLAG_FOR_CXX_14") diff --git a/Item35_Prefer_task-based_programming_to_thread-based/CMakeLists.txt b/Item35_Prefer_task-based_programming_to_thread-based/CMakeLists.txt index 667749a..706461b 100644 --- a/Item35_Prefer_task-based_programming_to_thread-based/CMakeLists.txt +++ b/Item35_Prefer_task-based_programming_to_thread-based/CMakeLists.txt @@ -1,10 +1,6 @@ -FIND_PACKAGE ( Threads REQUIRED ) - -add_executable(software_threads software_threads.cpp) -TARGET_LINK_LIBRARIES ( software_threads ${CMAKE_THREAD_LIBS_INIT} ) - -add_executable(task_based_approach task_based_approach.cpp) -TARGET_LINK_LIBRARIES ( task_based_approach ${CMAKE_THREAD_LIBS_INIT} ) - -add_executable(thread_based_approach thread_based_approach.cpp) -TARGET_LINK_LIBRARIES ( thread_based_approach ${CMAKE_THREAD_LIBS_INIT} ) +SET(SAMPLES_NAMES + software_threads + task_based_approach + thread_based_approach +) +subitems_add_executables("${SAMPLES_NAMES}" "ADD_FLAG_FOR_CXX_11;USE_PTHREAD") diff --git a/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/CMakeLists.txt b/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/CMakeLists.txt index cbdde0b..bed3997 100644 --- a/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/CMakeLists.txt +++ b/Item36_Specify_std_launch_async_if_asynchronicity_is_essential/CMakeLists.txt @@ -1,32 +1,16 @@ -FIND_PACKAGE ( Threads REQUIRED ) - -add_executable(default_launch_policy default_launch_policy.cpp) -# pas très propre, faudrait une version avec cmake ... -TARGET_LINK_LIBRARIES ( default_launch_policy ${CMAKE_THREAD_LIBS_INIT} ) - -add_executable(guaranteeing_truly_asynchronous_execution guaranteeing_truly_asynchronous_execution.cpp) -# pas très propre, faudrait une version avec cmake ... -TARGET_LINK_LIBRARIES ( guaranteeing_truly_asynchronous_execution ${CMAKE_THREAD_LIBS_INIT} ) - -add_executable(interesting_implications interesting_implications.cpp) -# pas très propre, faudrait une version avec cmake ... -TARGET_LINK_LIBRARIES ( interesting_implications ${CMAKE_THREAD_LIBS_INIT} ) - -add_executable(really_async_cpp11 really_async_cpp11.cpp) -TARGET_LINK_LIBRARIES ( really_async_cpp11 ${CMAKE_THREAD_LIBS_INIT} ) - -set_source_files_properties(really_async_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") -add_executable(really_async_cpp14 really_async_cpp14.cpp) -TARGET_LINK_LIBRARIES ( really_async_cpp14 ${CMAKE_THREAD_LIBS_INIT} ) - -add_executable(thread_local_storage thread_local_storage.cpp) -TARGET_LINK_LIBRARIES ( thread_local_storage ${CMAKE_THREAD_LIBS_INIT} ) - +SET(NAMES_SAMPLES + default_launch_policy + guaranteeing_truly_asynchronous_execution + interesting_implications + really_async_cpp11 + thread_local_storage +) +subitems_add_executables("${NAMES_SAMPLES}" "ADD_FLAG_FOR_CXX_11;USE_PTHREAD") + +SET(NAMES_SAMPLES + really_async_cpp14 + wait-based_loops + wait-based_loops_fixed +) +subitems_add_executables("${NAMES_SAMPLES}" "ADD_FLAG_FOR_CXX_14;USE_PTHREAD") # url: http://stackoverflow.com/questions/35856969/chrono-literals-is-not-a-namespace-name -set_source_files_properties(wait-based_loops.cpp PROPERTIES COMPILE_FLAGS "-std=gnu++14 -std=c++14") -add_executable(wait-based_loops wait-based_loops.cpp) -TARGET_LINK_LIBRARIES ( wait-based_loops ${CMAKE_THREAD_LIBS_INIT} ) - -set_source_files_properties(wait-based_loops_fixed.cpp PROPERTIES COMPILE_FLAGS "-std=gnu++14 -std=c++14") -add_executable(wait-based_loops_fixed wait-based_loops_fixed.cpp) -TARGET_LINK_LIBRARIES ( wait-based_loops_fixed ${CMAKE_THREAD_LIBS_INIT} ) diff --git a/Item37_Make_std_threads_unjoinable_on_all_paths/CMakeLists.txt b/Item37_Make_std_threads_unjoinable_on_all_paths/CMakeLists.txt index bfd243a..c74e3e3 100644 --- a/Item37_Make_std_threads_unjoinable_on_all_paths/CMakeLists.txt +++ b/Item37_Make_std_threads_unjoinable_on_all_paths/CMakeLists.txt @@ -1,7 +1,5 @@ -FIND_PACKAGE ( Threads REQUIRED ) - -add_executable(example1 example1.cpp) -TARGET_LINK_LIBRARIES ( example1 ${CMAKE_THREAD_LIBS_INIT} ) - -add_executable(example2 example2.cpp) -TARGET_LINK_LIBRARIES ( example2 ${CMAKE_THREAD_LIBS_INIT} ) +SET(SAMPLES_NAMES + example1 + example2 +) +subitems_add_executables("${SAMPLES_NAMES}" "ADD_FLAG_FOR_CXX_11;USE_PTHREAD") diff --git a/Item38_Be_aware_of_varying_thread_handle_destructor_behavior/CMakeLists.txt b/Item38_Be_aware_of_varying_thread_handle_destructor_behavior/CMakeLists.txt index 2357ded..2aea3ae 100644 --- a/Item38_Be_aware_of_varying_thread_handle_destructor_behavior/CMakeLists.txt +++ b/Item38_Be_aware_of_varying_thread_handle_destructor_behavior/CMakeLists.txt @@ -1,8 +1,14 @@ -# TODO: improve this CMakeLists.txt file. -FIND_PACKAGE ( Threads REQUIRED ) +subitem_add_library( + NAME item38_example1 + SRC example1.cpp + ADD_FLAG_FOR_CXX_11 + USE_PTHREAD +) -add_library(item38_example1 example1.cpp) -TARGET_LINK_LIBRARIES ( item38_example1 ${CMAKE_THREAD_LIBS_INIT} ) - -add_executable(item38_example2 example2.cpp) -TARGET_LINK_LIBRARIES ( item38_example2 ${CMAKE_THREAD_LIBS_INIT} ) +subitem_add_executable( + NAME item38_example2 + SRC example2.cpp + ADD_FLAG_FOR_CXX_11 + USE_PTHREAD +) +#ps: execution result -> 'terminate called without an active exception' diff --git a/Item38_Be_aware_of_varying_thread_handle_destructor_behavior/example2.cpp b/Item38_Be_aware_of_varying_thread_handle_destructor_behavior/example2.cpp index bfbc1b8..9764b28 100644 --- a/Item38_Be_aware_of_varying_thread_handle_destructor_behavior/example2.cpp +++ b/Item38_Be_aware_of_varying_thread_handle_destructor_behavior/example2.cpp @@ -2,7 +2,7 @@ #include #include -int calcValue() {}; // func to run +int calcValue() {} // func to run int main() { // begin block diff --git a/cmake/cmake_tools.cmake b/cmake/cmake_tools.cmake new file mode 100644 index 0000000..129e520 --- /dev/null +++ b/cmake/cmake_tools.cmake @@ -0,0 +1,110 @@ +macro(add_flags SRC_FILES FLAGS) +# MESSAGE("Flags list to add: ${FLAGS}") +# MESSAGE("to this sources files:") + foreach(src ${SRC_FILES}) +# MESSAGE("-> ${src}") + set_source_files_properties(${src} PROPERTIES COMPILE_FLAGS ${FLAGS}) + endforeach() +endmacro() + +macro(add_std_cxx14_flag SRC_FILES) + add_flags("${SRC_FILES}" "-std=c++14") +endmacro() + +macro(add_std_cxx11_flag SRC_FILES) + add_flags("${SRC_FILES}" "-std=c++11") +endmacro() + +function(SUBITEM_ADD) + set(options + IS_EXECUTABLE + IS_LIBRARY + USE_BOOST + USE_PTHREAD + ADD_FLAG_FOR_CXX_11 + ADD_FLAG_FOR_CXX_14 + PRINT_DEBUG) + set(oneValueArgs NAME) + set(multiValueArgs SRC) + cmake_parse_arguments(SUBITEM_ADD "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) + + ######################################################## + + IF(${SUBITEM_ADD_ADD_FLAG_FOR_CXX_11} MATCHES "TRUE") + add_std_cxx11_flag("${SUBITEM_ADD_SRC}") + ENDIF() + + IF(${SUBITEM_ADD_ADD_FLAG_FOR_CXX_14} MATCHES "TRUE") + add_std_cxx14_flag("${SUBITEM_ADD_SRC}") + ENDIF() + + ######################################################## + + IF(${SUBITEM_ADD_IS_EXECUTABLE} MATCHES "TRUE") + add_executable(${SUBITEM_ADD_NAME} ${SUBITEM_ADD_SRC}) + ENDIF() + + IF(${SUBITEM_ADD_IS_LIBRARY} MATCHES "TRUE") + add_library(${SUBITEM_ADD_NAME} ${SUBITEM_ADD_SRC}) + ENDIF() + + ######################################################## + + IF(${SUBITEM_ADD_USE_BOOST} MATCHES "TRUE") + target_link_libraries(${SUBITEM_ADD_NAME} ${Boost_LIBRARIES}) + ENDIF() + + IF(${SUBITEM_ADD_USE_PTHREAD} MATCHES "TRUE") + target_link_libraries( ${SUBITEM_ADD_NAME} ${CMAKE_THREAD_LIBS_INIT}) + ENDIF() + + ######################################################## + + IF(${SUBITEM_ADD_PRINT_DEBUG} MATCHES "TRUE") + foreach(option ${options}) + MESSAGE("- ${option} = ${SUBITEM_ADD_${option}}") + endforeach() + MESSAGE("* SUBITEM_ADD_NAME = ${SUBITEM_ADD_NAME}") + MESSAGE("# SUBITEM_ADD_SRC = ${SUBITEM_ADD_SRC}") + # +# #ps: problem with foreach => cause exception ! +# foreach(option ${oneValueArgs}) +# MESSAGE("- ${option} = ${SUBITEM_ADD_${option}}") +# foreach(option ${multiValueArgs}) +# MESSAGE("- ${option} = ${SUBITEM_ADD_${option}}") +# endforeach() + + MESSAGE("? IS_EXECUTABLE = ${SUBITEM_ADD_IS_EXECUTABLE}") + MESSAGE("? IS_LIBRARY = ${SUBITEM_ADD_IS_LIBRARY}") + ENDIF() + +endfunction() + +function(SUBITEM_ADD_EXECUTABLE) + subitem_add(IS_EXECUTABLE ${ARGN}) +endfunction(SUBITEM_ADD_EXECUTABLE) + +function(SUBITEM_ADD_LIBRARY) + subitem_add(IS_LIBRARY ${ARGN}) +endfunction(SUBITEM_ADD_LIBRARY) + +function(SUBITEMS_ADD_EXECUTABLES NAMES_SAMPLES FLAGS_FOR_SAMPLES) + foreach(name_sample ${NAMES_SAMPLES}) + subitem_add_executable( + NAME ${name_sample} + SRC ${name_sample}.cpp + ${FLAGS_FOR_SAMPLES} + ) + endforeach() +endfunction() + +function(SUBITEMS_ADD_LIBRARIES NAMES_SAMPLES FLAGS_FOR_SAMPLES) + foreach(name_sample ${NAMES_SAMPLES}) + subitem_add_library( + NAME ${name_sample} + SRC ${name_sample}.cpp + ${FLAGS_FOR_SAMPLES} + ) + endforeach() +endfunction() + From c5d7ca1a1969e27b3f06bcbcf56de453f400dcb2 Mon Sep 17 00:00:00 2001 From: ATTY Lionel Date: Wed, 11 May 2016 17:23:39 +0200 Subject: [PATCH 11/13] Fix and clean some scripts in CMakeLists.txt --- .../CMakeLists.txt | 19 ++++++------------- .../CMakeLists.txt | 18 +++--------------- .../CMakeLists.txt | 6 +----- .../CMakeLists.txt | 14 ++++---------- .../CMakeLists.txt | 6 +----- .../CMakeLists.txt | 6 +----- .../CMakeLists.txt | 6 +----- .../CMakeLists.txt | 17 ++--------------- .../CMakeLists.txt | 5 +---- .../CMakeLists.txt | 12 ++---------- .../CMakeLists.txt | 1 - cmake/cmake_tools.cmake | 1 + 12 files changed, 23 insertions(+), 88 deletions(-) diff --git a/Item02_Understand_auto_type_deduction/CMakeLists.txt b/Item02_Understand_auto_type_deduction/CMakeLists.txt index 3eb1e28..5201bfb 100644 --- a/Item02_Understand_auto_type_deduction/CMakeLists.txt +++ b/Item02_Understand_auto_type_deduction/CMakeLists.txt @@ -1,14 +1,7 @@ -subitem_add_executable( - NAME auto_type_deduction - SRC auto_type_deduction.cpp - ADD_FLAG_FOR_CXX_11) +SET(SAMPLES_NAMES + auto_type_deduction + auto_deduction_vs_template_deduction +) +subitems_add_executables("${SAMPLES_NAMES}" "ADD_FLAG_FOR_CXX_11") -subitem_add_executable( - NAME auto_deduction_vs_template_deduction - SRC auto_deduction_vs_template_deduction.cpp - ADD_FLAG_FOR_CXX_11) - -subitem_add_executable( - NAME function_return_type_deduction - SRC function_return_type_deduction.cpp - ADD_FLAG_FOR_CXX_14) +subitems_add_executables("function_return_type_deduction" "ADD_FLAG_FOR_CXX_14") diff --git a/Item04_Know_how_to_view_deduced_types/CMakeLists.txt b/Item04_Know_how_to_view_deduced_types/CMakeLists.txt index 1a0ce10..816309a 100644 --- a/Item04_Know_how_to_view_deduced_types/CMakeLists.txt +++ b/Item04_Know_how_to_view_deduced_types/CMakeLists.txt @@ -2,20 +2,8 @@ SET(NAMES_SAMPLES runtime_output01 runtime_output02 ) -SET(FLAGS_FOR_SAMPLES - ADD_FLAG_FOR_CXX_11 -) -subitems_add_executables("${NAMES_SAMPLES}" "${FLAGS_FOR_SAMPLES}") +subitems_add_executables("${NAMES_SAMPLES}" "ADD_FLAG_FOR_CXX_11") -subitem_add_executable( - NAME boost_type_index - SRC boost_type_index.cpp - ADD_FLAG_FOR_CXX_11 - USE_BOOST -) +subitems_add_executables("boost_type_index" "ADD_FLAG_FOR_CXX_11;USE_BOOST") -subitem_add_library( - NAME ide_editors - SRC compiler_diagnostics.cpp - ADD_FLAG_FOR_CXX_11 -) +subitem_add_library(NAME ide_editors SRC compiler_diagnostics.cpp ADD_FLAG_FOR_CXX_11) diff --git a/Item05_Prefer_auto_to_explicit_type_declarations/CMakeLists.txt b/Item05_Prefer_auto_to_explicit_type_declarations/CMakeLists.txt index a4cf041..009caaf 100644 --- a/Item05_Prefer_auto_to_explicit_type_declarations/CMakeLists.txt +++ b/Item05_Prefer_auto_to_explicit_type_declarations/CMakeLists.txt @@ -1,7 +1,3 @@ #TODO: wait until clang bug fixed!!! add_executable(auto auto.cpp) -subitem_add_library( - NAME simple_joys - SRC simple_joys.cpp - ADD_FLAG_FOR_CXX_11 -) +subitems_add_libraries("simple_joys" "ADD_FLAG_FOR_CXX_11") diff --git a/Item06_Use_the_explicitly_typed_initializer_idiom_when_auto_deduces_undesired_types/CMakeLists.txt b/Item06_Use_the_explicitly_typed_initializer_idiom_when_auto_deduces_undesired_types/CMakeLists.txt index 46dcc40..5df9fdf 100644 --- a/Item06_Use_the_explicitly_typed_initializer_idiom_when_auto_deduces_undesired_types/CMakeLists.txt +++ b/Item06_Use_the_explicitly_typed_initializer_idiom_when_auto_deduces_undesired_types/CMakeLists.txt @@ -1,16 +1,10 @@ # ps: exception in execution ! # TODO: debug this sample ! -subitem_add_executable( - NAME invisible_proxy_types - SRC invisible_proxy_types.cpp - ADD_FLAG_FOR_CXX_11 -) - -subitem_add_executable( - NAME typed_initializer_idiom - SRC typed_initializer_idiom.cpp - ADD_FLAG_FOR_CXX_11 +SET(NAME_SAMPLES + invisible_proxy_types + typed_initializer_idiom ) +subitems_add_executables("${NAMES_SAMPLES}" "ADD_FLAG_FOR_CXX_11") #subitem_add_executable( # NAME matrix_example diff --git a/Item07_Distinguish_between()_and_{}_when_creating_objects/CMakeLists.txt b/Item07_Distinguish_between()_and_{}_when_creating_objects/CMakeLists.txt index 8fb6016..315a2b5 100644 --- a/Item07_Distinguish_between()_and_{}_when_creating_objects/CMakeLists.txt +++ b/Item07_Distinguish_between()_and_{}_when_creating_objects/CMakeLists.txt @@ -7,8 +7,4 @@ SET(NAMES_SAMPLES initializer_lists4 parenthesis_braces_in_templates ) -SET(FLAGS_FOR_SAMPLES - ADD_FLAG_FOR_CXX_11 -) - -subitems_add_executables("${NAMES_SAMPLES}" "${FLAGS_FOR_SAMPLES}") +subitems_add_executables("${NAMES_SAMPLES}" "ADD_FLAG_FOR_CXX_11") diff --git a/Item08_Prefer_nullptr_to_0_and_NULL/CMakeLists.txt b/Item08_Prefer_nullptr_to_0_and_NULL/CMakeLists.txt index d17e508..f0bec1b 100644 --- a/Item08_Prefer_nullptr_to_0_and_NULL/CMakeLists.txt +++ b/Item08_Prefer_nullptr_to_0_and_NULL/CMakeLists.txt @@ -6,8 +6,4 @@ SET(NAMES_SAMPLES ) subitems_add_executables("${NAMES_SAMPLES}" "ADD_FLAG_FOR_CXX_11") -subitem_add_executable( - NAME template_example_templatized_cpp14 - SRC template_example_templatized_cpp14.cpp - ADD_FLAG_FOR_CXX_14 -) +subitems_add_executables("template_example_templatized_cpp14" "ADD_FLAG_FOR_CXX_14") diff --git a/Item09_Prefer_alias_declarations_to_typedefs/CMakeLists.txt b/Item09_Prefer_alias_declarations_to_typedefs/CMakeLists.txt index d4296d5..aca8227 100644 --- a/Item09_Prefer_alias_declarations_to_typedefs/CMakeLists.txt +++ b/Item09_Prefer_alias_declarations_to_typedefs/CMakeLists.txt @@ -6,8 +6,4 @@ SET(SRC_FILES linked_list_synonym_with_typedef02.cpp # TODO wine.cpp ) -subitem_add_library( - NAME item09 - SRC ${SRC_FILES} - ADD_FLAG_FOR_CXX_11 -) +subitem_add_library(NAME item09 SRC ${SRC_FILES} ADD_FLAG_FOR_CXX_11) diff --git a/Item10_Prefer_scoped_enums_to_unscoped_enums/CMakeLists.txt b/Item10_Prefer_scoped_enums_to_unscoped_enums/CMakeLists.txt index 83cd06e..fea0d01 100644 --- a/Item10_Prefer_scoped_enums_to_unscoped_enums/CMakeLists.txt +++ b/Item10_Prefer_scoped_enums_to_unscoped_enums/CMakeLists.txt @@ -1,4 +1,4 @@ -SET(SRC_FILES_Cxx11 +SET(SRC_FILES scoped_enums.cpp semantic_travesties01.cpp semantic_travesties02.cpp @@ -11,19 +11,6 @@ SET(SRC_FILES_Cxx11 unscoped_enums_useful03.cpp unscoped_enums_useful04.cpp ) -add_std_cxx11_flag("${SRC_FILES_Cxx11}") +subitem_add_library(NAME item10 SRC ${SRC_FILES} ADD_FLAG_FOR_CXX_11) -add_library(item10 unscoped_enums.cpp - scoped_enums.cpp - semantic_travesties01.cpp - semantic_travesties02.cpp - semantic_travesties03.cpp - forward_declaring.cpp - forward_declared_enums.cpp - underlying_type01.cpp - underlying_type02.cpp - unscoped_enums_useful01.cpp - unscoped_enums_useful02.cpp - unscoped_enums_useful03.cpp - unscoped_enums_useful04.cpp) # TODO: compile C++14 code unscoped_enums_useful04_cpp14.cpp) diff --git a/Item11_Prefer_deleted_functions_to_private_undefined_ones/CMakeLists.txt b/Item11_Prefer_deleted_functions_to_private_undefined_ones/CMakeLists.txt index d790de8..e60e914 100644 --- a/Item11_Prefer_deleted_functions_to_private_undefined_ones/CMakeLists.txt +++ b/Item11_Prefer_deleted_functions_to_private_undefined_ones/CMakeLists.txt @@ -1,7 +1,4 @@ -subitem_add_executable( - NAME Item12 - SRC Item12.cpp - ADD_FLAG_FOR_CXX_11) +subitems_add_executables("Item12" "ADD_FLAG_FOR_CXX_11") SET(NAMES_SAMPLES pointer_example diff --git a/Item13_Prefer_const_iterators_to_iterators/CMakeLists.txt b/Item13_Prefer_const_iterators_to_iterators/CMakeLists.txt index b1918dd..d94675d 100644 --- a/Item13_Prefer_const_iterators_to_iterators/CMakeLists.txt +++ b/Item13_Prefer_const_iterators_to_iterators/CMakeLists.txt @@ -1,13 +1,5 @@ add_executable(insertion_cpp98 insertion_cpp98.cpp) -subitem_add_executable( - NAME insertion_cpp11 - SRC insertion_cpp11.cpp - ADD_FLAG_FOR_CXX_11 -) +subitems_add_executables("insertion_cpp11" "ADD_FLAG_FOR_CXX_11") -subitem_add_executable( - NAME insertion_cpp14 - SRC insertion_cpp14.cpp - ADD_FLAG_FOR_CXX_14 -) +subitems_add_executables("insertion_cpp14" "ADD_FLAG_FOR_CXX_14") diff --git a/Item23_Understand_std_move_and_std_forward/CMakeLists.txt b/Item23_Understand_std_move_and_std_forward/CMakeLists.txt index 9d7216e..af3172c 100644 --- a/Item23_Understand_std_move_and_std_forward/CMakeLists.txt +++ b/Item23_Understand_std_move_and_std_forward/CMakeLists.txt @@ -6,7 +6,6 @@ SET(SRC_FILES_Cxx11 typical_use_of_std_forward.cpp ) add_std_cxx11_flag("${SRC_FILES_Cxx11}") - add_std_cxx14_flag("std_move_in_cpp14.cpp") add_executable(typical_use_of_std_forward diff --git a/cmake/cmake_tools.cmake b/cmake/cmake_tools.cmake index 129e520..5c2e851 100644 --- a/cmake/cmake_tools.cmake +++ b/cmake/cmake_tools.cmake @@ -16,6 +16,7 @@ macro(add_std_cxx11_flag SRC_FILES) endmacro() function(SUBITEM_ADD) + # url: https://cmake.org/cmake/help/v3.0/module/CMakeParseArguments.html set(options IS_EXECUTABLE IS_LIBRARY From d946af1baaf5a8ae951b52293fef0d454cd23b3d Mon Sep 17 00:00:00 2001 From: ATTY Lionel Date: Wed, 11 May 2016 17:27:50 +0200 Subject: [PATCH 12/13] remove some 'set_source_files_properties' --- .../pimpl_unique_ptr/CMakeLists.txt | 3 ++- Item34_Prefer_lambdas_to_std_bind/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/pimpl_unique_ptr/CMakeLists.txt b/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/pimpl_unique_ptr/CMakeLists.txt index b156b58..1e94730 100644 --- a/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/pimpl_unique_ptr/CMakeLists.txt +++ b/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/pimpl_unique_ptr/CMakeLists.txt @@ -5,7 +5,8 @@ add_std_cxx11_flag("${SRC_FILES_Cxx11}") include_directories(../) -set_source_files_properties(widget.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") +#set_source_files_properties(widget.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") +add_std_cxx14_flag("$widget.cpp") add_library(widget_pimpl_unique_ptr widget.cpp) diff --git a/Item34_Prefer_lambdas_to_std_bind/CMakeLists.txt b/Item34_Prefer_lambdas_to_std_bind/CMakeLists.txt index 6bb27fb..174e58f 100644 --- a/Item34_Prefer_lambdas_to_std_bind/CMakeLists.txt +++ b/Item34_Prefer_lambdas_to_std_bind/CMakeLists.txt @@ -1,4 +1,4 @@ -set_source_files_properties(alarm_with_lambda_cpp11.cpp PROPERTIES COMPILE_FLAGS "-std=gnu++14 -std=c++14") +#set_source_files_properties(alarm_with_lambda_cpp11.cpp PROPERTIES COMPILE_FLAGS "-std=gnu++14 -std=c++14") add_executable(alarm_with_lambda_cpp11 alarm_with_lambda_cpp11.cpp) #set_source_files_properties(alarm_with_lambda_cpp14.cpp PROPERTIES COMPILE_FLAGS "-std=c++14 -stdlib=libc++") From d81a517e4513f8660f6bc3e7981d9d2087a3c8af Mon Sep 17 00:00:00 2001 From: ATTY Lionel Date: Thu, 12 May 2016 11:14:51 +0200 Subject: [PATCH 13/13] Add scripts to configure and build with cmake and gcc-4.9. Fix some a bug with Item22 --- .../pimpl_unique_ptr/CMakeLists.txt | 2 +- build.sh | 5 +++++ configure.sh | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100755 build.sh create mode 100755 configure.sh diff --git a/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/pimpl_unique_ptr/CMakeLists.txt b/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/pimpl_unique_ptr/CMakeLists.txt index 1e94730..3b45cf8 100644 --- a/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/pimpl_unique_ptr/CMakeLists.txt +++ b/Item22_When_using_the_Pimpl_Idiom_define_special_member_functions_in_the_implementation_file/pimpl_unique_ptr/CMakeLists.txt @@ -6,7 +6,7 @@ add_std_cxx11_flag("${SRC_FILES_Cxx11}") include_directories(../) #set_source_files_properties(widget.cpp PROPERTIES COMPILE_FLAGS "-std=c++14") -add_std_cxx14_flag("$widget.cpp") +add_std_cxx14_flag("widget.cpp") add_library(widget_pimpl_unique_ptr widget.cpp) diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..8fdbe53 --- /dev/null +++ b/build.sh @@ -0,0 +1,5 @@ +cd ../build/Effective-Modern-Cpp/gcc-4.9 + +make -j3 + +cd - \ No newline at end of file diff --git a/configure.sh b/configure.sh new file mode 100755 index 0000000..214b717 --- /dev/null +++ b/configure.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +mkdir -p ../build/Effective-Modern-Cpp/gcc-4.9 +cd ../build/Effective-Modern-Cpp/gcc-4.9 + +# url: http://evadeflow.com/2013/11/static-analysis-with-clangscan-build/ +cmake ../../../Effective-Modern-Cpp/ + +cd - \ No newline at end of file