Skip to content
Merged
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
3 changes: 3 additions & 0 deletions code/smartPointers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
cmake_minimum_required( VERSION 3.1 )
project( smartPointers LANGUAGES CXX )

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Set up the compilation environment.
include( "${CMAKE_CURRENT_SOURCE_DIR}/../CompilerSettings.cmake" )
include( "${CMAKE_CURRENT_SOURCE_DIR}/../SolutionTarget.cmake" )
Expand Down
2 changes: 1 addition & 1 deletion code/smartPointers/smartPointers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ double sumEntries(const double* data, std::size_t size) {
if (size > 200)
throw std::invalid_argument("I only want to sum 200 numbers or less.");

return std::accumulate(data, data + size, 0);
return std::reduce(data, data + size, 0);
}

// Often, data are owned by one entity, and only used by others. Fix the leak.
Expand Down
2 changes: 1 addition & 1 deletion code/smartPointers/solution/smartPointers.sol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ double sumEntries(const double* data, std::size_t size) {
if (size > 200)
throw std::invalid_argument("I only want to sum 200 numbers or less.");

return std::accumulate(data, data + size, 0.);
return std::reduce(data, data + size, 0.);
}

// Often, data are owned by one entity, and only used by others. Fix the leak.
Expand Down
3 changes: 3 additions & 0 deletions code/stl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
cmake_minimum_required( VERSION 3.1 )
project( stl LANGUAGES CXX )

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Set up the compilation environment.
include( "${CMAKE_CURRENT_SOURCE_DIR}/../CompilerSettings.cmake" )
include( "${CMAKE_CURRENT_SOURCE_DIR}/../SolutionTarget.cmake" )
Expand Down
6 changes: 3 additions & 3 deletions code/stl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ clean:
rm -f *o randomize *~ randomize.sol randomize.nostl

randomize : randomize.cpp
${CXX} -g -O0 -Wall -Wextra -L. -o $@ $<
${CXX} -std=c++17 -g -O0 -Wall -Wextra -L. -o $@ $<

randomize.nostl : randomize.nostl.cpp
${CXX} -g -O0 -Wall -Wextra -L. -o $@ $<
${CXX} -std=c++17 -g -O0 -Wall -Wextra -L. -o $@ $<

randomize.sol : solution/randomize.sol.cpp
${CXX} -g -O0 -Wall -Wextra -I. -L. -o $@ $<
${CXX} -std=c++17 -g -O0 -Wall -Wextra -I. -L. -o $@ $<
5 changes: 2 additions & 3 deletions code/stl/randomize.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <random>
#include "Complex.hpp"

using namespace std;
using namespace __gnu_cxx;

template<typename T>
struct Generator {
Expand All @@ -20,7 +19,7 @@ void compute(int len, T initial, T step) {

// fill and randomize v
generate(, , Generator...);
random_shuffle(...);
shuffle(..., std::default_random_engine{});

// compute differences
adjacent_difference(...);
Expand Down
9 changes: 4 additions & 5 deletions code/stl/solution/randomize.sol.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <random>
#include "Complex.hpp"

using namespace std;
using namespace __gnu_cxx;

template<typename T>
struct Generator {
Expand All @@ -31,14 +30,14 @@ void compute(int len, T initial, T step) {

// fill and randomize v
generate(v.begin(), v.end(), Generator<T>(initial, step));
random_shuffle(v.begin(), v.end());
shuffle(v.begin(), v.end(), std::default_random_engine{});

// compute differences
adjacent_difference(v.begin(), v.end(), diffs.begin());

// compute standard deviation of it
T sum = accumulate(diffs.begin()+1, diffs.end(), T());
T sumsq = accumulate(diffs.begin()+1, diffs.end(), T(), sumsquare<T>());
T sum = reduce(diffs.begin()+1, diffs.end(), T());
T sumsq = reduce(diffs.begin()+1, diffs.end(), T(), sumsquare<T>());
T mean = sum/len;
T variance = sumsq/len - mean*mean;

Expand Down