(1) VS 2015 cannot compile constexpr with statement body.
(2) Eclipse CDT (C++ dev tool) can but need the following install/setup/config
(3) cdt need compiler and cygwin64 must be installed (latest version 2.6.0)
(4) C++ 17 is supported in 2.6.0 but may not be supported in MinGW.
(5) during cygwin64 install to c:\cygwin64, must install package under devel--gcc,g++, make, gdb
(6) cdt download is cdt 9.1.0 =Eclipse neon 1.
(7) windows->preference->C/C++->Environment add path c:\cygwin64\bin
(8) project ->properties->C/C++ build ->Toolchain Editor ->Current Toolchain=CygWin gcc, builder=CDT internal builder
(9) same as (8), C++ compiler->settings->includes "C:\cygwin64\lib\gcc\x86_64-w64-mingw32\5.4.0\include"
(10) same as (9) C++ compiler->misc->other flag -std=c++17
(11) project ->C/C++ index -> rebuild/search/un-resolved can help to find out why some include are not found
(12) right click on a project can also access properties
#include <iostream>
#include <cmath>
using namespace std;
constexpr bool is_prime(int i)
{
if (i == 1) return false;
if (i % 2 == 0)
return i == 2;
double max_check =sqrt(i) + 1;
for (int j = 3; j < max_check; j += 2)
if (i%j == 0) return false;
return true;
}
using namespace std;
int main() {
cout << "test " <<is_prime(67)<< endl;
return 0;
}
contexpr with recursion and new if statement
constexpr bool is_prime2(int i, int div)
{
return div>=i?true:(i%div==0?false:is_prime2(i,div+2));
}
constexpr bool is_prime(int i)
{
return i==1?false:(i%2==0?i==2:is_prime2(i,3));
}
Saturday, October 8, 2016
Set Up IDE to compile C++17 code constexpr with statement, recursion in body
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment