Skip to content

Commit

Permalink
Merge pull request #19 from gjbex/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
gjbex authored Mar 1, 2023
2 parents ebc5e03 + e960346 commit 70c5919
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 17 deletions.
Binary file modified scientific_cpp.pptx
Binary file not shown.
35 changes: 35 additions & 0 deletions source-code/Algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
cmake_minimum_required(VERSION 3.0)
project(algorithms LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMaKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)

add_compile_options(-Wall -Wextra -Wpedantic)

add_executable(find_if.exe
find_if.cpp)
add_executable(permutations.exe
permutations.cpp)
add_executable(generate.exe
generate.cpp)
add_executable(for_each.exe
for_each.cpp)
add_executable(particle_sort.exe
particle_sort.cpp)
add_executable(count_clamp.exe
count_clamp.cpp)
add_executable(find_words.exe
find_words.cpp)
add_executable(zip_it.exe
zip_it.cpp)
add_executable(accumulate.exe
accumulate.cpp)
add_executable(distance.exe
distance.cpp)
add_executable(iota.exe
iota.cpp)
add_executable(transform.exe
transform.cpp)
add_executable(points.exe
points.cpp)
16 changes: 0 additions & 16 deletions source-code/Algorithms/Makefile

This file was deleted.

3 changes: 2 additions & 1 deletion source-code/Algorithms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ Code illustrations for chapter 10, Algorithms in Stroustrup's
1. `distances.cpp`: illustrating a `std::back_inserter` in an
`std::transform`.
1. `iota.cpp`: initialize a `valarray` using `iota` and apply a function.
1. `Makefile`: make file to build the code.
1. `points.cpp`: illustration of using C++20's spaceship operator.
1. `CMakeLists.txt`: CMake file to build the code.
29 changes: 29 additions & 0 deletions source-code/Algorithms/points.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <algorithm>
#include <compare>
#include <iostream>
#include <vector>

struct Point {
double x, y;
int id;
auto operator<=>(const Point&) const = default;
friend std::ostream& operator <<(std::ostream& out, const Point& p);
};

std::ostream& operator <<(std::ostream& out, const Point& p) {
return out << p.id << ": (" << p.x << ", " << p.y << ")";
}

int main() {
std::vector<Point> points;
points.emplace_back(4.1, 5.2, 1);
points.emplace_back(2.1, 7.2, 2);
points.emplace_back(1.2, 9.2, 3);
points.emplace_back(2.1, 3.2, 4);
points.emplace_back(2.1, 3.2, 5);
std::sort(points.begin(), points.end());
for (const auto& point: points) {
std::cout << point << "\n";
}
return 0;
}

0 comments on commit 70c5919

Please sign in to comment.