What is the point of `std::make_optional`

One example of the difference is when you want (for whatever reason) to make an optional containing an optional: #include <optional> #include <type_traits> int main() { auto inner=std::make_optional(325); auto opt2=std::make_optional(inner); // makes std::optional<std::optional<int>> auto opt3=std::optional(inner); // just a copy of inner static_assert(std::is_same_v<decltype(opt2), std::optional<std::optional<int>>>); static_assert(std::is_same_v<decltype(opt3), std::optional<int>>); }

Why is partial class template argument deduction impossible?

From this excellent trip report by Botond Ballo: The feature as originally proposed included a provision for partial deduction, where you explicitly specify some of the template arguments, and leave the rest to be deduced, but this was pulled over concerns that it can be very confusing in some cases: // Would have deduced tuple<int, … Read more

How to avoid specifying arguments for a class template with default template arguments

Note: Foo me; without template arguments is legal as of C++17. See this answer: https://stackoverflow.com/a/50970942/539997. Original answer applicable before C++17: You have to do: Foo<> me; The template arguments must be present but you can leave them empty. Think of it like a function foo with a single default argument. The expression foo won’t call … Read more

tech