Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set::vector initialization with quotes in a numeric

Tags:

c++

c++17

stl

So I came about a question about std::reduce which lead me to an example on. cppreference.com

In this example I saw the following std::vector declaration:

    std::vector<double> v(10'000'007, 0.5);

What are these quotes doing here? I've never seen this before anywhere. Is this a new kind of C++ feature that I should know about?

like image 835
Nils Pipenbrinck Avatar asked Jan 29 '23 06:01

Nils Pipenbrinck


2 Answers

This is a new feature in C++14. From cppreference:

Optional single quotes(') may be inserted between the digits as a separator. They are ignored by the compiler.

like image 101
Kevin Avatar answered Feb 12 '23 09:02

Kevin


It appears to be a digit separator, as described in here: http://www.informit.com/articles/article.aspx?p=2209021

So, this code should be equivalent to

std::vector<double> v(10000007, 0.5);
like image 36
Pablo Oliva Avatar answered Feb 12 '23 09:02

Pablo Oliva