Reputation: 619
cmake_minimum_required(VERSION 3.16)
project(competitive_programming)
set(CMAKE_CXX_STANDARD 17)
add_executable(competitive_programming main.cpp)
As you see, I'm using C++ 17, and I want to use if initializer to keep the code neat,
if (auto result = right.find(second); result != right.end()){
result->second--;
}
But the compiler does not work as is supposed to be,
The readout seems as follows:
error: expected ')' before ';' token
if (auto result = right.find(item); result == right.end()){error: expected ')' before ';' token
if (auto result = right.find(item); result == right.end()){
My compiler is so, I guess:
g++ (x86_64-posix-seh, Built by strawberryperl.com project) 8.3.0
Upvotes: 1
Views: 89
Reputation: 9173
Try adding:
set(CMAKE_CXX_STANDARD_REQUIRED ON)
to your CMakeLists.txt
. It makes sure that you are compiling with C++17 and it is not decayed to previous versions of compiler.
Upvotes: 3