Noureldin's blog

By Noureldin, 9 years ago, In English

for a competitive programmer the most important features are what C++11 has already introduced namely (range based loops ,lambda expressions ,brace initialization of aggregates, unordered containers ,..... etc) which can be found here .

in addition to:

1) numeric literals

now you can separate digits of a number with single quotes ( ' ) to improve readability

auto num = 10'000'000; // num = 10^7

this works for floating numbers as well

auto fnum = 0.000'015'3; // fnum = 1.53 * 10^-5

now you can initialize numbers using their binary form this feature was experimentally included in C++0x (the prototype of C++11) however it didn't become official until the announcement of the new standard

auto bnum = 0b0100'1100'0110; // bnum = (010011000110)2 = (4C6)16 = 1222

//note that the spacing of the quotes doesn't matter

auto snum = 1'0'0'000'00; // snum = 10^7

2) std::gets was removed due to its tendency to cause RTE due to overflow in its buffer

3) lambda expressions can now be generic:

in C++11 you had to specify the type of the inputs to the lambda expression

auto lambda = [](int x, int y) {return x + y;}; // C++11 --- had to specify type of x and y
auto lambda = [](auto x, auto y) {return x + y;}; // C++14 the compiler will decide the type for you ;)

4) improved std::tuple (in particular improved std::get)

in std::tuple introduced by C++11 (which was experimentally added to TR1 in 2007) to get the value of an element you had to use only its index

int element = std::get<2>(mytuple); //get the third element in mytuple

now you can do the same thing plus the ability to index by type

std::string element = std::get<string>(mytuple);// return the string element in mytuple

note: if the tuple had more than one element of the same type using std::get that way would cause compilation error


a feature of C++11 that's not mentioned in the link above that I find very useful

C++11 introduced the ability to pass rvalues by reference that's to pass temporary values by reference such as

// compilation error in C++03 .... legit in C++11 & C++14
string mul(string && a,string && b); 
mul("10","30");

as you can see from the specific example I used ,it speeds up calculuations in particular this snippet is from my biginteger implementation which sped up biginteger multiplication by 30-40% on average (tested on numbers containing ~ 50000 digits)


note: some legit C++03 && C++11 codes might break if compiled using C++14 standards

codes that use std::gets are the simplest case but there are others for more details you can refer to this link


finally ,there are some other additions and modifications in C++14 that are very important (relaxed constexpr restrictions ,improved lambda capture expressions ,the attribute [[deprecated]] ,heterogeneous lookup ,....etc) to name a few, yet their importance to a competitive programmer is less than that of the mentioned features (at least from my point of view)

  • Vote: I like it
  • +57
  • Vote: I do not like it

»
9 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Does anyone know if there is a chance that C++14 will be available at IOI'15?

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I can see that gets() does not cause a compilation error at codeforces with C++14 but it causes a compilation error for C++14 or even C++11 at codechef. Does anyone know what might be the difference between the compilers of codeforces and codechef which is causing this?