dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: C++17: possibilities and examples

Hybrid View

  1. #1
    Join Date
    Mar 2016
    Posts
    35

    Post C++17: possibilities and examples

    Due to constant С++ extension developers have to be in-the-know and regularly follow all the changes, introduced by the new standard. So, new possibilities and rules have been introduced in C++17. GCC, Clang, Visual Studio compiler developers are already actively adding them.

    One of the developers of PVS-Studio static code analyzer wrote an overview article with the most interesting innovations and also demonstrated them with examples.

    For instance, new logical meta functions std::conjunction, std:: disjunction and std::negation have been introduced. They are used to perform a logical AND, OR, NOT on a set of traits, respectively. Here is also a small example with std::conjunction:

    Code:
    // C++17
    #include <iostream>
    #include <string>
    #include <algorithm>
    #include <functional>
    
    template<typename... Args>
    std::enable_if_t<std::conjunction_v<std::is_integral<Args>...>>
    Func(Args... args)
    {
      std::cout << "All types are integral.\n";
    }
    
    template<typename... Args>
    std::enable_if_t<!std::conjunction_v<std::is_integral<Args>...>>
    Func(Args... args)
    {
      std::cout << "Not all types are integral.\n";
    }
    
    int main()
    {
      Func(42, true); // All types are integral.
      Func(42, "hello"); // Not all types are integral. 
    
      return 0;
    }

    Besides, the article touches upon such examples, as:

    • Fold expressions
    • template<auto>
    • Class template argument deduction
    • Constexpr if
    • Constexpr lambdas
    • *this capture in lambda expressions
    • inline variables
    • Structured bindings
    • Initializer in 'if' and 'switch'
    • __has_include
    • and many other interesting features



    The full version of the article is available by the link: https://www.viva64.com/en/b/0533/

  2. #2
    Join Date
    Oct 2019
    Posts
    11

    Re: C++17: possibilities and examples

    Thanкs a lot. It's a very useful information.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)