C++ Tip of The Week


Your weekly dose of modern C++ challenge (Release every Sunday).

  • How to contribute/add a solution?

    • Contributions are always very much appreciated. Just create a Pull Request with your solution.

Tips

  • [270] - Did you know that C++23 added std::to_underlying?
  • [269] - Did you know about boost::mp11::mp_with_index?
  • [268] - Did you know that C++20 added std::erase_if for std::map and std::vector?
  • [267] - Did you know that C++23 added std::unreachable?
  • [266] - Did you know wrapping an unqualified function name in parentheses suppresses argument-dependent lookup?
  • [265] - Did you know that C++23 added Attributes on Lambda-Expressions?
  • [264] - Did you know that C++20 added __VA_OPT__ for comma omission and comma deletion?
  • [263] - Did you know that C++23 added std::byteswap to swap bytes?
  • [262] - Did you know that type_info equality operator is constexpr in C++23?
  • [261] - Did you know that C++23 added Monadic operations for std::optional?
  • [260] - Did you know that C++23 added std::move_only_function?
  • [259] - Did you know that static reflection supports introspecting constructors?
  • [258] - Did you know that static reflection can be used to invoke functions with named parameters?
  • [257] - Did you know that static reflection can be used to implement row polymorphism?
  • [256] - Did you know that static reflection proposal for C++2X has mirror/value based interface?
  • [255] - Did you know that static reflection proposal for C++2X can reflect functions?
  • [254] - Did you know about static reflection proposal for C++2X?
  • [253] - Did you know that C++20 extends support for data time utilities?
  • [252] - Did you know that C++23 added basic_string::resize_and_overwrite?
  • [251] - Did you know that C++20 added type_identity which implements the identity metafunction?
  • [250] - Did you know about methods to access the last element of variadic pack...?
  • [249] - Did you know that C++23 allows extended init-statement with alias-declaration in the for loop?
  • [248] - Did you know that CRTP can be implemented with C++23 Deducing this?
  • [247] - Did you know that Deducing this proposal has been voted out into C++23?
  • [246] - Did you know that C++11 added a numeric literal operator template?
  • [245] - Did you know about C++2X proposal to add Multidimensional subscript operator?
  • [244] - Did you know about compiler predefined macros assosicated with the compilation date/time?
  • [243] - Did you know about C++2X Pattern matching using is and as proposal?
  • [242] - Did you know that ANSI/ISO C++ conforming programs must not rely on a maximum template depth greater than 17 (changed to 1024 in C++11)?
  • [241] - Did you know about different ways of accessing C-style arrays by index?
  • [240] - Did you know that using-declarator can be used to manipulate the overload set?
  • [239] - Did you know that Circle Meta-model allows to convert string to a type?
  • [238] - Did you know that Circle Meta-model allows for applying normal STL for operations on @meta types?
  • [237] - Did you know about C++2X proposal for the Circle Meta-model for compilation-time meta-programming?
  • [236] - Did you know about __builtin_dump_struct clang-extension which can nicely print a struct?
  • [235] - Did you know that C++20 [[no_unique_address]] can be used to implement lazy/fast/memory efficient views?
  • [234] - Did you know about function-try-block and that exceptions caught inside that block are implicitly rethrown?
  • [233] - Did you know that C++20 made typename more optional?
  • [232] - Did you know that different overloads can have different specifiers?
  • [231] - Did you know about C++17 variadic using declaration?
  • [230] - Did you know that C++23 added if consteval?
  • [229] - Did you know about python's named tuples?
  • [228] - Did you know that C++ allows accessing private members with friend injection?
  • [227] - Did you know that std::variant become valueless by exception?
  • [226] - Did you know about C++23 feature which adds support for inheriting from std::variant?
  • [225] - Did you know about C++23 feature which removes unnecessary ()’s from C++ lambdas?
  • [224] - Did you know that the JSON standard does not specify that the insertion order of object elements should be preserved?
  • [223] - Did you know about the proposal to add json support to the standard library?
  • [222] - Did you know that C++23 added contains function to string_view?
  • [221] - Did you know that with Automatic DI production wiring can be overwritten for integration testing?
  • [220] - Did you know that with Automatic DI one can control how dependencies are being created?
  • [219] - Did you know about Automatic Dependency Injection libraries such as DI?
  • [218] - Did you know about different ways of constructor Dependency Injection?
  • [217] - Did you know the difference between fakes, stubs, mocks?
  • [216] - Did you know that you can inject singletons to improve testability?
  • [215] - Did you know C++2X Pattern Matching can be used for run-time dispatching?
  • [214] - Did you know about variadic aggregate initialization?
  • [213] - Did you know that mapping types to values is a simple way to transition from compile-time to run-time space?
  • [212] - Did you know that lambdas are const by default but can be mutable and keep state?
  • [211] - Did you know about C++2X Pattern Matching proposal?
  • [210] - Did you know about Design By Introspection?
  • [209] - Did you know about Policy Based Design?
  • [208] - Did you know that default template arguments can be explored with template template arguments?
  • [207] - Did you know about the proposal to add constexpr function parameters?
  • [206] - Did you know about proposal to add support for recursive lambdas?
  • [205] - Did you know that C++20 std::to_array supports creating from string literals?
  • [204] - Did you know that you can implement a compile-time map with C++?
  • [203] - Did you know that in C++ char, signed char and unsigned char are 3 different types?
  • [202] - Did you know that C++20 added Using Enum which introduces the enumerator names of the named enumeration as if by a using-declaration for each enumerator?
  • [201] - Did you know that sizeof operator can be used for efficient math computation?
  • [200] - Did you know that C++23 added is_scoped_enum type trait to detect whether an enum is scoped?
  • [199] - Did you know about proposal to introduce constexpr ternary operator?
  • [198] - Did you know about different ways of iterating over objects?
  • [197] - Did you know that Lambdas in Unevaluated Context combined with Template Constraints (Concepts) can be used with types?
  • [196] - Did you know that Lambdas in Unevaluated Context combined with Immediately Invoked Function Expressions (IIEF) can be used to simplify Template Meta-Programming?
  • [195] - Did you know that C++20 added support for [[no_unique_address]] attribute?
  • [194] - Did you know about C++23 proposal to add views::enumerate?
  • [193] - Did you know that C++20 added support for constexpr new?
  • [192] - Did you know about std::expected proposal for error handling?
  • [191] - Did you know that expression evaluation order is not specified?
  • [190] - Did you know that C++20 added ostream_joiner that writes successive objects into the basic_ostream separated by a delimiter?
  • [189] - Did you know that Compile Time Regular Expressions support extracting matches?
  • [188] - Did you know about proposal to add Compile Time Regular Expressions?
  • [187] - Did you know that C++17 made exception specifications be part of the type system?
  • [186] - Did you know Non-Type Template Parameters (NTTP) with User-Defined Literals (UDL) can be used to get compile-time strings?
  • [185] - Did you know about the proposal to make printf compile-time safe and with named arguments?
  • [184] - Did you know that you can customize formatter for your classes with std::format?
  • [183] - Did you know that Formatted output has been accepted into C++20?
  • [182] - Did you know about the proposal to add Non-terminal variadic template parameters?

  • Did you know about C++20 make_unique_for_overwrite?
  • Did you know aboutproposal to allow floating-points as non-typetemplate parameters (NTTP)?
  • Did you know about std::rank/std::rank_v type_trait to get the rank?
  • Did you know that C++20 added std::destroying_delete?
  • Did you know about C++ allows to pass Pointer To Member Function?
  • Did you know that C++20 added Class Types in Non-Type Template
  • Did you that C++ introduced std::to_address (Utility to convert a
  • Did you that you about proposal to make std::type_info constexpr?
  • Did you that you that C++20 added ranges?
  • Did you know that Ranges will be added to C++20 as an STL improvement?
  • Did you that you that C++20 added functions for safe integral
  • Did you that you boost::mp11 allows meta-functions to be used with
  • Did you that you C++ concepts can be used to constraint functions
  • Did you that you can create anonymous structs with different types in
  • Did you know that C++17 added std::forward_as_tuple?
  • Did you know that C++20 added std::is_corresponding_member?
  • Did you know that C++20 added shift_left, shift_right algorithms?
  • Did you know that C++20 added concepts library?
  • Did you know that C++20 added jthread which can be interrupted?
  • Did you know about C++23 proposal for a type trait to detectection?
  • Did you know about C++2a proposal - Universal Template Parameters (UTP) which would allow to unify TMP with types and values?
  • Did you know that C++20 added Class Types in Non-Type Template Parameters
  • Did you know that about GNU extension – Statement Expressions – available
  • Did you know that with C++2a getting an enum name in a standard/compatible
  • Did you know that C++20 extended make_shared to support arrays?
  • Did you know that C++17 fold expressions might be applied to make
  • Did you know that C++20 added span view over contiguous containers?
  • Did you know that C++20 added Three-way comparison (aka spaceship
  • Did you know that C++20 added Class Types in Non-Type Template
  • Did you know that C++20 added std::bit_cast?
  • Did you know that C++20 added std::to_array?
  • Did you know about std::embed proposal for C++23?
  • Did you know that C++20 modules have support for private sections?
  • Did you know that C++20 added type_traits to verify whether array is
  • Did you know that C++20 made std::for_each constexpr?
  • Did you know that order of fields in tuple/struct may impact the sizeof
  • Did you know that C++17 added Class Template Class Deduction (C++20
  • Did you know that C++20’s added bind_front to simplify writing higher
  • Did you know that C++20’s requires expression (added by concepts) can be
  • Did you know that C++20 added Integral power-of-2 operations in
  • Did you know that C++20 added String Prefix and Suffix Checking?
  • Did you know that C++20 adopted source location to access
  • Did you know that with C++11 auto trailing return type Substitution
  • Did you know that with C++17 class template argument deduction can be
  • Did you know that C++20 added support for allowing pack expansion in
  • Did you know that expansion statements (also known as for... and/or
  • Did you know that C++20 is going to add text formatting library (based
  • Did you know that with C++20 you can capture reference of structured
  • Did you know that you can ensure that NON-constexpr evaluation by simply
  • Did you know that with C++ you create a compile-time unique string type
  • Did you know that with C++ you can reflect on type name using nonstandard PRETTY_FUNCTION extensions (should be possible with source.location
  • Did you know that C++20 unified template<class…> class and
  • Did you know that with C++20 and lambdas in unevaluated context you can
  • Did you know that C++17 added std::invoke?
  • Did you know that C++20 added template-parameter-list for generic
  • Did you know that you can overload on derived types?
  • Did you know that with modern C++ it’s possible to implement well
  • Did you that C++20 unfortunately won’t have function traits?
  • Did you know that template template types can be used for type traits?
  • Did you know that C++20 won’t have a packed attribute which, if applied,
  • Did you know that C++20 unfortunately won’t have static reflection?
  • Did you know that C++20 added support for a new type_trait
  • Did you know that C++20 will allow Virtual Function Calls in Constant
  • Did you know that C++20 will add [[no_unique_address]] attribute?
  • Did you know that C++20 will add support for checking whether a call
  • Did you know that C++20 will add support for ‘Familiar template syntax
  • Did you know that C++20 will add support for ‘Class Types in Non-Type
  • Did you know that with DI you can write your own extensions?
  • Did you know that with DI you can restrict types which can be injected?
  • Did you know that dependency injection in C++ can be automated?
  • Did you know you can implement named parameters using modern C++?
  • Did you know that with modern C++ you can make TMP almost without <>?
  • Did you know about Boost.MP11 library for Template Meta-Programming
  • Did you know that Ranges will be added to C++20 as an STL improvement?
  • Did you know Boost.Hana library (Your standard library for
  • Did you know that C++17 added support for auto with templates (non-type template parameters)?
  • Did you know that C++17 added support for constexpr if?
  • Did you know that constexpr if can help with suppor(ng different API’s?
  • Did you know that C++17 added init-statements for if and switch?
  • Did you know that C++17 added support for fold expressions?
  • Did you know that C++17 introduced Parallel STL? (Another reason not to write raw loops?)
  • Did you know about trigraphs? Don’t worry if you didn’t because from C++17 trapgrahs are DEPRACTED
  • Did you know that C++17 introduced a few new general ajributes and that one of them is [[nodiscard]]?
  • Did you know that C++17 added [[maybe_unused]] general ajribute?
  • Did you know that C++17 introduced [[fallthrough]] ajribute? It indicates that the fall through from the
  • Did you know that excep(on specifica(ons is part of the type system since C++17?
  • Did you know about new C++17 SFINAE helpers: std::is_detected and std::void_t?
  • Did you know that it’s possible to use SFINAE in order to detect whether a func(on is constexpr?
  • Did you know that pseudo-random numbers might be generated at compile (me?
  • Did you know that you can verify whether a template is instan(ated within the transla(on unit?
  • Did you know that C++17 added support for auto with templates (non-type template
  • Did you know that C++17 added support for constexpr if?
  • Did you know that constexpr if can help with supporBng different API’s?
  • Did you know that C++17 added init-statements for if and switch?
  • Did you know that C++17 added support for fold expressions?
  • Did you know that C++17 introduced Parallel STL? (Another reason not to write raw loops?)
  • Did you know about trigraphs? Don’t worry if you didn’t because from C++17 trapgrahs are
  • Did you know that C++17 introduced a few new general a6ributes and that one of them is
  • Did you know that C++17 added [[maybe_unused]] general a6ribute?
  • Did you know that C++17 introduced [[fallthrough]] a6ribute? It indicates that the fall
  • Did you know that exception specification is part of the type system since C++17?
  • Did you know about new C++17 SFINAE helpers: std::is_detected and std::void_t?
  • Did you know that it’s possible to use SFINAE in order to detect whether a function is
  • Did you know that pseudo-random numbers might be generated at compile Bme?
  • Did you know that you can verify whether a template is instanBated within the
  • Did you know that C++17 added support for auto with templates (non-type template
  • Did you know that C++17 added support for constexpr if?
  • Did you know that constexpr if can help with supporBng different API’s?
  • Did you know that C++17 added init-statements for if and switch?
  • Did you know that C++17 added support for fold expressions?
  • Did you know that C++17 introduced Parallel STL? (Another reason not to write raw loops?)
  • Did you know about trigraphs? Don’t worry if you didn’t because from C++17 trapgrahs are
  • Did you know that C++17 introduced a few new general a6ributes and that one of them is
  • Did you know that C++17 added [[maybe_unused]] general a6ribute?
  • Did you know that C++17 introduced [[fallthrough]] a6ribute? It indicates that the fall
  • Did you know about new C++17 SFINAE helpers: std::is_detected and std::void_t?
  • Did you know that it’s possible to use SFINAE in order to detect whether a funcBon is
  • Did you know that pseudo-random numbers might be generated at compile Bme?
  • Did you know that you can verify whether a template is instanBated within the
  • Did you know that C++17 added support for auto with templates (non-type template
  • Did you know that C++17 added support for constexpr if?
  • Did you know that constexpr if can help with supporort for different API’s?
  • Did you know that C++17 added init-statements for if and switch?
  • Did you know that C++17 added support for fold expressions?
  • Did you know that C++17 introduced Parallel STL? (Another reason not to write raw loops?)
  • Did you know about trigraphs? Don’t worry if you didn’t because from C++17 trapgrahs are
  • Did you know that C++17 introduced a few new general a6ributes and that one of them is
  • Did you know that C++17 added [[maybe_unused]] general a6ribute?
  • Did you know that C++17 introduced [[fallthrough]] a6ribute? It indicates that the fall
  • Did you know that excepBon specificaBons is part of the type system since C++17?
  • Did you know about new C++17 SFINAE helpers: std::is_detected and std::void_t?
  • Did you know that it’s possible to use SFINAE in order to detect whether a funcBon is
  • Did you know that pseudo-random numbers might be generated at compile Bme?
  • Did you know that you can verify whether a template is instanBated within the
  • Did you know Boost.Hana library (Your standard library for
  • Did you know that UML state machine standard offers more than just
  • Did you know that with modern C++ allows to implement declarative, zero
  • Did you know that variadic templates expansion is ‘greedy’?
  • Did you know about generic overload func(on (std::overload)?
  • Did you know about generic overload function (std::overload)?
  • Did you know that with variadic templates creating a list of types is
  • Did you know that about a powerful combination of std::is_base_of and
  • Did you know about restricted template expansion (aka stateless TMP)?
  • Did you know that C++20 introduced coroutines?
  • Did you know that C++17 introduced std::any?
  • Did you know that C++17 introduced structured bindings?
  • Did you know that C++17 introduced std::invoke which allows call any
  • Did you know that concepts checking might be combined with fold
  • Did you know that concepts (type requirements checking) were added to
  • Did you know that modern C++ allows to easily implement type erased
  • Did you know that C++17 introduce std::variant?
  • Did you know that a caught exception might be rethrown using throw
  • Did you know how type_traits are implemented in C++?
  • Did you about new utilities added in C++17 -> std::index_sequence?
  • Did you know that with SFINAE it can be detected whether a function can
  • Did you know that func(on parameters can’t be constexpr?
  • Did you know that function parameters can’t be constexpr?
  • Did you know that C++11 introduced alignof operator which queries
  • Did you know that C++17 introduced is_aggregate trait which checks whether a
  • Did you know that C++11 introduced user defined literals?
  • Did you know that C++17 added std::apply which invokes the callable object f with a tuple of
  • Did you know that C++17 added is_detected trait to simplify type introspection?
  • Did you know that C++17 added new type traits to the type_traits header?
  • Did you know that you can easily implement a run-time dispatching with modern C++?
  • Did you know that you can get a type name at compile-time (no RTTI)?

Disclaimer Quantlab Financial is not responsible for the correction of solutions and/or reserves the right to contact/reward contributors.