I am using the optional feature for the 1st time, any idea what is wrong in this code I wish to retrieve the value from the tuple which is stored in retCode
#include <iostream>
#include <experimental/optional>
std::experimental::optional<std::tuple<uint16_t, uint32_t, uint32_t>> addEntity();
std::experimental::optional<std::tuple<uint16_t, uint32_t, uint32_t>> addEntity() {
uint32_t ipR = 1111;
uint32_t ipU = 2222;
uint16_t entityId = 0;
return std::make_tuple(entityId, ipR, ipU);
}
int main()
{
auto retCode = addEntity();
std::cout<<std::get<0>(retCode)<<std::endl;
return 0;
}
Compilation Errors
g++ experiment.cpp
In file included from /usr/include/c++/7/bits/move.h:54:0,
from /usr/include/c++/7/bits/nested_exception.h:40,
from /usr/include/c++/7/exception:143,
from /usr/include/c++/7/ios:39,
from /usr/include/c++/7/ostream:38,
from /usr/include/c++/7/iostream:39,
from experiment.cpp:1:
/usr/include/c++/7/type_traits: In instantiation of ‘struct std::is_trivially_destructible<std::tuple<short unsigned int, unsigned int, unsigned int> >’:
/usr/include/c++/7/experimental/optional:203:5: required from ‘class std::experimental::fundamentals_v1::optional<std::tuple<short unsigned int, unsigned int, unsigned int> >’
Aucun commentaire:
Enregistrer un commentaire