Discussion of chess software programming and technical issues.
Moderators: hgm , Rebel , chrisw
Rein Halbersma
Posts: 741 Joined: Tue May 22, 2007 11:13 am
Post
by Rein Halbersma » Mon Mar 08, 2021 10:23 pm
Code: Select all
#include <array>
constexpr auto mapping = [] {
std::array<int, 128> ret{};
ret['K'] = 1;
ret['Q'] = 2;
return ret;
}();
Or you can just use an immediately invoked lambda expression
ydebilloez
Posts: 163 Joined: Tue Jun 27, 2017 11:01 pm
Location: Lubumbashi
Full name: Yves De Billoëz
Post
by ydebilloez » Tue Mar 09, 2021 3:43 pm
Thanks
Rein Halbersma wrote: ↑ Mon Mar 08, 2021 10:23 pm
Code: Select all
constexpr auto mapping = [] {
std::array<int, 128> ret{};
}();
Sesse wrote: ↑ Mon Mar 08, 2021 7:37 pm
combining this gives:
Code: Select all
// .h
class bEvaluation {
protected:
static std::array<int, 128> bPieceIndex;
// .cpp
auto bEvaluation::bPieceIndex = [] {
std::array<int, 128> bIndex{0};
bIndex['K'] = 1;
// etc
warning: declaration requires a global constructor
But lets say, we went halfway around the problem in some way. A static array does not need a destructor...
I still have some related problems:
Code: Select all
appInstance& App() {
static appInstance instance;
// declaration requires exit time constructor
return instance;
}
void classname::functname(param) const
{
static std::string sName = "Hello";
warning: declaration requires exit time constructor
Sesse
Posts: 300 Joined: Mon Apr 30, 2018 11:51 pm
Post
by Sesse » Wed Mar 10, 2021 4:24 pm
You need the constexpr part.
ydebilloez
Posts: 163 Joined: Tue Jun 27, 2017 11:01 pm
Location: Lubumbashi
Full name: Yves De Billoëz
Post
by ydebilloez » Thu Mar 25, 2021 1:40 pm
Using a simple global c array ended up easier in C++11...
Still stuck on static std::string X = "" in a function that gives the same error.
I assure you, I can fix it with a simple static char[255]... But I want to keep it c++11 and at the same time getting rid of the destructor error warning.