Cambo Freelance
HomeServicesArticlesTutorialsTeamCoursesContact
Cambo Freelance

Professional freelance team from Cambodia delivering technology-driven solutions with cultural insight and modern expertise.

Send us a message

Ready to start your project? Get in touch with our team.

Contact Us

Services

  • Web & Mobile Development Services
  • Graphic Design & Branding Services

Useful Links

  • Home
  • Services
  • Learning
  • About Us
  • Contact
  • Pricing

© 2026 Cambo Freelance. រក្សាសិទ្ធិទាំងអស់។

TelegramFacebookLinkedInEmail
HomeTutorialsC++C++17 Features
⚡C++ Tutorials

50 lessons

Beginner(21)1C++ Introduction2C++ Getting Started3C++ Syntax4C++ Output5C++ Comments6C++ Variables7C++ Data Types8C++ Constants9C++ User Input10C++ Operators11C++ Strings12C++ Math13C++ Booleans14C++ Conditions15C++ Switch16C++ Loops17C++ Break and Continue18C++ Arrays19C++ Functions20C++ References21C++ Pointers
Intermediate(19)22C++ Classes23C++ Objects24C++ Constructors25C++ Access Specifiers
Advanced(10)41C++ Smart Pointers42C++ Templates43C++ Lambda Functions44
⚡

C++ Tutorials

Lesson 48 of 50

All lessons
Beginner (21)1C++ Introduction2C++ Getting Started
26
C++ Encapsulation
27C++ Inheritance
28C++ Polymorphism
29C++ Abstraction
30C++ Files
31C++ Exception Handling
32C++ Namespaces
33C++ Structures
34C++ Enumerations
35C++ STL Introduction
36C++ Vectors
37C++ Maps
38C++ Sets
39C++ Queues
40C++ Stacks
C++ Move Semantics
45C++ Multithreading
46C++ Design Patterns
47C++ Memory Management
48C++17 Features
49C++20 Features
50C++ Performance Optimization
3
C++ Syntax
4C++ Output
5C++ Comments
6C++ Variables
7C++ Data Types
8C++ Constants
9C++ User Input
10C++ Operators
11C++ Strings
12C++ Math
13C++ Booleans
14C++ Conditions
15C++ Switch
16C++ Loops
17C++ Break and Continue
18C++ Arrays
19C++ Functions
20C++ References
21C++ Pointers
Intermediate (19)22C++ Classes23C++ Objects24C++ Constructors25C++ Access Specifiers26C++ Encapsulation27C++ Inheritance28C++ Polymorphism29C++ Abstraction30C++ Files31C++ Exception Handling32C++ Namespaces33C++ Structures34C++ Enumerations35C++ STL Introduction36C++ Vectors37C++ Maps38C++ Sets39C++ Queues40C++ Stacks
Advanced (10)41C++ Smart Pointers42C++ Templates43C++ Lambda Functions44C++ Move Semantics45C++ Multithreading46C++ Design Patterns47C++ Memory Management48C++17 Features49C++20 Features50C++ Performance Optimization
⚡C++AdvancedLesson 48 of 50CamboFreelanceJune 19, 2026

C++17 Features

Explore C++17 features: structured bindings, std::optional, if initializers, std::filesystem, and if constexpr.


Tutorials › C++ › C++17 Features
Advanced10 min readLesson 48 of 50

Key C++17 Features

C++17 added powerful features that make code cleaner and more expressive. Compile with -std=c++17.

Structured Bindings

#include <iostream>
#include <map>
#include <tuple>
using namespace std;

int main() {
    // Decompose pair
    map<string,int> scores = {{"Alice",95},{"Bob",82}};
    for (auto& [name, score] : scores) {
        cout << name << ": " << score << endl;
    }

    // Decompose tuple
    auto [x, y, z] = make_tuple(1, 2.5, "hello");
    cout << x << " " << y << " " << z << endl;
    return 0;
}

std::optional

Represents a value that may or may not be present — safer than returning -1 or null:

#include <optional>

optional<int> divide(int a, int b) {
    if (b == 0) return nullopt;
    return a / b;
}

auto result = divide(10, 2);
if (result.has_value())
    cout << "Result: " << *result << endl;  // 5

auto bad = divide(5, 0);
cout << bad.value_or(-1) << endl;           // -1

if with Initializer

map<string,int> m = {{"key", 42}};

if (auto it = m.find("key"); it != m.end()) {
    cout << "Found: " << it->second << endl;
}
// 'it' not visible outside the if

std::filesystem

#include <filesystem>
namespace fs = filesystem;

fs::create_directory("output");
for (const auto& entry : fs::directory_iterator(".")) {
    cout << entry.path() << endl;
}

Quiz

  1. What does std::optional<int> represent?

    • A) An int that can be negative
    • B> A value that might or might not be present
    • C) A thread-safe integer
    • D> An optional parameter
    Answer

    B) std::optional holds either a value or nullopt.

Summary

  • Structured bindings: auto [a, b] = pair — unpack tuples and maps cleanly.
  • std::optional: express "value or nothing" without magic sentinel values.
  • if (init; cond): scoped variable in if condition.
  • std::filesystem: portable file and directory operations.
← Previous: Memory Management Next: C++20 Features →
c++cpp17modern-cppadvanced
PreviousLesson 47: C++ Memory ManagementNextLesson 49: C++20 Features
Back to All Tutorials