I have got an Element, which is a std::vector in a std::optional. Now I want to emplace an Element to the vector (via emplace_back):
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <optional>
int main()
{
std::optional<std::vector<uint8_t>> optvec;
optvec->reserve(1);
optvec->emplace_back(1);
std::cout << optvec.has_value() << std::endl;
return 0;
}
However, regarding the memory, this emplaces the element itself correctly, but the optional part doesn't get it that there is an element, so it's a nullopt.
Is there another way to do this? Thanks in advance.