Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gcc 4.9 #4

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ CMakeFiles
cmake_install.cmake
CMakeCache.txt
*.so
CMakeLists.txt.user
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 2.6)

project(Effective_Modern_C++ CXX)
#project(Effective_Modern_C++ C CXX)
project(Effective_Modern_C++ C CXX)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why exactly must C be added here? Shouldn't the project be completely CXX?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's for (cmake) pthread compatibility.
Adding pthread like i do include some tests files (intern codes) to check if pthread is accessible for the current system.
It's a CMake mechanism (througth 'FindThreads.cmake').

MMmMMMM after reading the file 'FindThreads.cmake' (https://github.com/Kitware/CMake/blob/master/Modules/FindThreads.cmake) i'm not sure it's necessary after all ... i will check tomorrow to remove this line.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oki ... seems strange ... maybe a bug (fix) from CMake.
In my system (from official package 'cmake') in FindThreads.cmake i don't have in the script a test for switching between C and CXX project (like in: https://github.com/Kitware/CMake/blob/master/Modules/FindThreads.cmake around line 94-99).
Maybe the depot (for Ubuntu14.04/Mint) isn't synchronized with the depot of the last release of CMake.
Whatever, with my version (CMake 3.2.2) i need to to add C flag to permit the build of the test file 'CheckForPthreads.c' needed by CMake & 'FindThreads.cmake' to check if a PThread lib is available (with a default/system path).
With the last release of CMake (from github depot), it will not be necessary anymore.


# Uncomment this to use clang++ to compile.
#SET (CMAKE_CXX_COMPILER "/usr/bin/clang++-3.5")
Expand All @@ -9,7 +10,13 @@ project(Effective_Modern_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)
Expand Down
31 changes: 19 additions & 12 deletions Item01_Understand_template_type_deduction/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
10 changes: 6 additions & 4 deletions Item02_Understand_auto_type_deduction/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
set_source_files_properties(function_return_type_deduction.cpp PROPERTIES COMPILE_FLAGS -std=c++14)
SET(SAMPLES_NAMES
auto_type_deduction
auto_deduction_vs_template_deduction
)
subitems_add_executables("${SAMPLES_NAMES}" "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)
subitems_add_executables("function_return_type_deduction" "ADD_FLAG_FOR_CXX_14")
22 changes: 12 additions & 10 deletions Item03_Understand_decltype/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
14 changes: 7 additions & 7 deletions Item04_Know_how_to_view_deduced_types/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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
)
subitems_add_executables("${NAMES_SAMPLES}" "ADD_FLAG_FOR_CXX_11")

add_library(ide_editors.cpp
compiler_diagnostics.cpp)
subitems_add_executables("boost_type_index" "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)
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
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)
subitems_add_libraries("simple_joys" "ADD_FLAG_FOR_CXX_11")
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
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 !
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
# SRC matrix_example.cpp
# ADD_FLAG_FOR_CXX_11
#)
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
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
)
subitems_add_executables("${NAMES_SAMPLES}" "ADD_FLAG_FOR_CXX_11")
16 changes: 8 additions & 8 deletions Item08_Prefer_nullptr_to_0_and_NULL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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
#add_executable(template_example_templatized_cpp14 template_example_templatized_cpp14.cpp)
subitems_add_executables("template_example_templatized_cpp14" "ADD_FLAG_FOR_CXX_14")
16 changes: 9 additions & 7 deletions Item09_Prefer_alias_declarations_to_typedefs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
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)
28 changes: 15 additions & 13 deletions Item10_Prefer_scoped_enums_to_unscoped_enums/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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)
SET(SRC_FILES
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
)
subitem_add_library(NAME item10 SRC ${SRC_FILES} ADD_FLAG_FOR_CXX_11)

# TODO: compile C++14 code unscoped_enums_useful04_cpp14.cpp)
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
add_executable(Item12 Item12.cpp)
add_library(pointer_example pointer_example.cpp)
add_library(Widget Widget.cpp)
subitems_add_executables("Item12" "ADD_FLAG_FOR_CXX_11")

SET(NAMES_SAMPLES
pointer_example
Widget
)
subitems_add_libraries("${NAMES_SAMPLES}" "ADD_FLAG_FOR_CXX_11")
23 changes: 16 additions & 7 deletions Item12_Declare_overriding_functions_override/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 4 additions & 2 deletions Item13_Prefer_const_iterators_to_iterators/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
add_executable(insertion_cpp98 insertion_cpp98.cpp)
# TODO: find out why this doesn't compile!!! add_executable(insertion_cpp11 insertion_cpp11.cpp)
# TODO add_executable(insertion_cpp11 insertion_cpp14.cpp)

subitems_add_executables("insertion_cpp11" "ADD_FLAG_FOR_CXX_11")

subitems_add_executables("insertion_cpp14" "ADD_FLAG_FOR_CXX_14")
19 changes: 14 additions & 5 deletions Item13_Prefer_const_iterators_to_iterators/insertion_cpp14.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -32,6 +41,6 @@ int main()

std::vector<int> values; // as before

findAndInsert(values, 1983, 1998)
findAndInsert(values, 1983, 1998);

}
Original file line number Diff line number Diff line change
@@ -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
)
16 changes: 13 additions & 3 deletions Item16_Make_const_member_functions_thread-safe/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# TODO: complete this CMakeLists.txt
#add_executable(insertion_cpp98 insertion_cpp98.cpp)
add_executable(undefined_behavior undefined_behavior.cpp)
subitem_add_executable(
NAME expensive_int
SRC expensive_int.cpp
ADD_FLAG_FOR_CXX_11
)

subitem_add_executable(
NAME undefined_behavior
SRC undefined_behavior.cpp
ADD_FLAG_FOR_CXX_11
USE_PTHREAD
)

#add_library(roots Polynomial.cpp)
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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")
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
add_executable(creation creation.cpp)
subitem_add_executable(
NAME creation
SRC creation
ADD_FLAG_FOR_CXX_11
)
Original file line number Diff line number Diff line change
@@ -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")
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int main()
std::unique_ptr<Widget, decltype(widgetDeleter)>
upw(new Widget(), widgetDeleter);

std::shared_ptr<Widget> spw(new Widget(), widgetDeleter);
// std::shared_ptr<Widget> spw(new Widget(), widgetDeleter);


// Limitation 2: within the make function, the perfect forwarding code uses
Expand Down Expand Up @@ -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<ReallyBigType> pBigObj(new ReallyBigType);
std::shared_ptr<ReallyBigType> pBigObj_2(new ReallyBigType);
// create very large
// object via new

Expand Down
Loading