Skip to content

Commit

Permalink
Remove pragma guards for C++17
Browse files Browse the repository at this point in the history
This project already requires C++17, so these pragma guards are no
longer needed. This patch removes them from "strings_1_main.cpp".
  • Loading branch information
banach-space committed Nov 24, 2024
1 parent 59ad4bc commit 8b5f596
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.4.3 FATAL_ERROR)
cmake_minimum_required(VERSION 3.20)

project(cpp-tutor)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Set the `CMAKE_BUILD_TYPE` variable to:
configured to be run with address sanitzer

### Switching between C++ standards
The default C++ standard for the whole project is set to C++14. In order to
The default C++ standard for the whole project is set to C++17. In order to
rebuild using `C++11` or `C++17`, use `CMAKE_CXX_STANDARD`. For example, to
build in `C++17` mode:
```bash
Expand Down
10 changes: 0 additions & 10 deletions src/strings_1_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
#include <algorithm>
#include <iostream>
#include <string>
#if __cplusplus >= 201703L
#include <string_view>
#endif

#include "../include/strings_reverse.hpp"

Expand All @@ -38,19 +36,15 @@ int main(int argc, const char** argv) {
// trigger UB. Hence `const char*` is what makes most sense here.
const char* hello_c_c = "Hello World!";
std::string hello_cpp(hello_c);
#if __cplusplus >= 201703L
std::string_view hello_sv(hello_cpp);
#endif

//-------------------------------------------------------------------------
// 2. PRINT THE STRINGS
//-------------------------------------------------------------------------
std::cout << "C-string (char[]): " << hello_c << std::endl;
std::cout << "C-string (const char*): " << hello_c_c << std::endl;
std::cout << "C++ string: " << hello_cpp << std::endl;
#if __cplusplus >= 201703L
std::cout << "C++ string_view: " << hello_sv << std::endl;
#endif
std::cout << std::endl;

//-------------------------------------------------------------------------
Expand All @@ -59,9 +53,7 @@ int main(int argc, const char** argv) {
std::cout << "Size of hello_c: " << sizeof(hello_c) << std::endl;
std::cout << "Size of hello_c_c: " << sizeof(hello_c_c) << std::endl;
std::cout << "Size of hello_cpp: " << sizeof(hello_cpp) << std::endl;
#if __cplusplus >= 201703L
std::cout << "Size of hello_sv: " << sizeof(hello_sv) << std::endl;
#endif
std::cout << std::endl;

//-------------------------------------------------------------------------
Expand All @@ -82,14 +74,12 @@ int main(int argc, const char** argv) {
reverse_cpp_str_alg(&hello_cpp);
std::cout << "Reverse of hello_cpp: " << hello_cpp << std::endl;

#if __cplusplus >= 201703L
#ifdef COMPILATION_ERROR
// string_view is non-modifiable!
reverse_cpp_str_swap(&hello_sv);
reverse_cpp_str_alg(&hello_sv);
std::reverse(hello_sv.begin(), hello_sv.end());
std::cout << "Reverse of hello_sv: " << hello_sv << std::endl;
#endif
#endif

cppt::footer(argv[0]);
Expand Down

0 comments on commit 8b5f596

Please sign in to comment.