Sunday

C++20 (or C++2a), C++ 2020, Cpp 2020, g++ 2020

Subject: C++ 2020

4
contracts example

/**
C++ 2020 contracts
$ g++ -fcontracts -std=c++20 cpp2020_contracts.cpp
**/
 
#include <iostream>
using namespace std;

void f(int x)
[[ pre: x >= 0 ]]  // contracts line
{
}

int main()
{
  f (1);  // ok
  f (0);  // ok
  f (-1); // oops

  return 0;
}


3

ranges example

#include <iostream>
#include <ranges>

int main() {
    for(int i : std::views::iota(1,4)) {
        std::cout << i << " ";  // 1 2 3
    }
    std::cout << "\n";

    return EXIT_SUCCESS; 
}


2
The best parts of C++ 2020, the key features of C++ 2020

The big five feature updates of C++ 2020
- concepts
- coroutines
- ranges
- modules
- text formatting


1
Web links

C++ module, export, import
https://en.cppreference.com/w/cpp/language/modules

Compilers support for C++20
https://en.cppreference.com/w/cpp/compiler_support/20

Online C++ 2020 compiler godbolt or compiler explorer
https://gcc.godbolt.org/
Menu > Add new > Execution only
Tab on the Compilation
Select: x86-64 gcc (trunk)
Compiler options: type: -std=c++2a

No comments:

Measure execution time with Julia, example using sorting algorithms

# random integers between 1 and 100 inclusive, generate thousands of them x = rand ( 1 : 100 , 100000 ) @time sort (x; alg=InsertionSort, r...