We may earn an affiliate commission when you visit our partners.

C++17

C++17 is a major revision of the C++ programming language, released in 2017. It introduces several new features and improvements that make it easier to write efficient, safe, and maintainable code.

Why Learn C++17?

Read more

C++17 is a major revision of the C++ programming language, released in 2017. It introduces several new features and improvements that make it easier to write efficient, safe, and maintainable code.

Why Learn C++17?

There are many reasons why you might want to learn C++17. If you are a professional programmer, learning C++17 can help you write better code and keep up with the latest developments in the field. If you are a student, learning C++17 can give you a strong foundation for a career in programming.

What You Will Learn

In this article, we will discuss some of the key features of C++17, including:

  • Structured bindings
  • Fold expressions
  • Lambdas
  • Constexpr functions
  • Static assert

We will also provide examples of how to use these features in your own code.

Structured Bindings

Structured bindings allow you to unpack the values of a tuple or struct into individual variables. This can make your code more readable and easier to maintain.

For example, the following code unpacks the values of a tuple into three variables:

auto [x, y, z] = std::make_tuple(1, 2, 3);

This is equivalent to the following code:

int x = std::get<0>(std::make_tuple(1, 2, 3)); int y = std::get<1>(std::make_tuple(1, 2, 3)); int z = std::get<2>(std::make_tuple(1, 2, 3));

Fold Expressions

Fold expressions allow you to apply a binary operator to a range of values. This can be useful for performing common operations such as summing or multiplying a list of values.

For example, the following code sums the values in a list of integers:

int sum = std::accumulate(std::begin(values), std::end(values), 0);

This is equivalent to the following code:

int sum = 0; for (int value : values) { sum += value; }

Lambdas

Lambdas are anonymous functions that can be used to define inline code blocks. They are often used to pass code as arguments to other functions or to create closures.

For example, the following code defines a lambda function that squares a number:

auto square = [](int x) { return x * x; };

This lambda function can be used as an argument to the std::transform function to square each element in a list of integers:

std::vector squared_values = std::transform(std::begin(values), std::end(values), square);

Constexpr Functions

Constexpr functions are functions that can be evaluated at compile time. This means that they can be used to generate compile-time constants and to perform compile-time checks.

For example, the following code defines a constexpr function that calculates the factorial of a number:

constexpr int factorial(int n) { return n == 0 ? 1 : n * factorial(n - 1); }

This constexpr function can be used to generate a compile-time constant for the factorial of a number:

constexpr int factorial_5 = factorial(5); // 120

Static Assert

Static assert is a compile-time check that can be used to verify that a condition is true. If the condition is false, the compiler will issue an error.

For example, the following code uses static assert to check that a value is greater than zero:

static_assert(value > 0, "Value must be greater than zero");

If the value is not greater than zero, the compiler will issue the following error:

error: static assertion failed: Value must be greater than zero

Conclusion

C++17 is a powerful and expressive programming language that can be used to write efficient, safe, and maintainable code. By learning C++17, you can open up new possibilities for your programming career.

How Online Courses Can Help

There are many online courses available that can help you learn C++17. These courses can provide you with the skills and knowledge you need to succeed in your programming career.

Online courses can provide you with the following benefits:

  • Structured learning environment
  • Expert instruction
  • Hands-on practice
  • Assessment and feedback

Online courses can be a great way to learn C++17. They can provide you with the flexibility and support you need to succeed.

Are Online Courses Enough?

Online courses can be a helpful learning tool, but they are not enough to fully understand C++17. To fully understand C++17, you will need to practice writing code and applying it to real-world problems.

The best way to learn C++17 is to combine online courses with other learning resources, such as books, tutorials, and practice projects.

Share

Help others find this page about C++17: by sharing it with your friends and followers:

Reading list

We've selected eight books that we think will supplement your learning. Use these to develop background knowledge, enrich your coursework, and gain a deeper understanding of the topics covered in C++17.
An in-depth exploration of C++17 features and best practices, focusing on resource management, generics, and concurrency. Written by a renowned C++ expert, this book offers valuable insights for experienced programmers looking to master modern C++ techniques.
Explores advanced C++ design techniques, focusing on generic programming and design patterns. It provides a deep understanding of how to write reusable, efficient, and maintainable C++ code.
This updated edition of the classic book on the C++ Standard Library provides a comprehensive collection of recipes and examples for using the library effectively. It covers all the major components, including containers, algorithms, and functions, making it a valuable resource for programmers of all levels.
This updated edition of the classic book on C++ templates provides a comprehensive and in-depth exploration of this powerful feature. It covers both the fundamentals and advanced topics, making it a valuable resource for programmers of all levels.
A practical guide to concurrency in C++17, covering topics such as threads, locks, and synchronization. With numerous code examples and exercises, this book is ideal for programmers who want to learn how to write concurrent and multithreaded applications.
This concise reference provides a quick and easy way to lookup information about the C++17 Standard Library. It covers all the major components, including containers, algorithms, and functions, making it a valuable resource for programmers of all levels.
Our mission

OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.

Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.

Find this site helpful? Tell a friend about us.

Affiliate disclosure

We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.

Your purchases help us maintain our catalog and keep our servers humming without ads.

Thank you for supporting OpenCourser.

© 2016 - 2024 OpenCourser