Tuesday, November 15, 2016

setup Eclipse CDT and optional in c++ 17

(1) create an empty project, cygwin gcc, all the include will be cygwin x86_64, no need to set include path in proj props
(2) set misc flag to have -std=c++17 (lower case)
(3) make sure tool chain editor set CDT internal builder
(4) ignore red squiggles and may rebuild C++ indexes.
(5) how to find C++ header file http://en.cppreference.com/w/cpp/header
(6) sometimes, include file still see "unresolved" error, e.g std::function in . This is caused by preprocessor
    proj->props->C++ general->Preprocessor..etc.->CDT gcc build-in Compiler Settings->uncheck use global, add -std=c++14

 #include <experimental\optional>

using namespace std;
using namespace std::experimental;

optional<pair<string,int>> to_roman(int n)
{
 if(n>10) return {{"X",n-20}};
 if(n>9) return {{"IX",n-9}};
 if(n>5) return {{"V",n-5}};
 if(n>4) return {{"IV",n-4}};
 if(n>1) return {{"I",n-1}};
 return nullopt;  // constexpr inside experimental\optional
}

No comments:

Post a Comment