I have a class T, it looks like this:
class T {
uint64_t id;
std::string description;
char status;
uint64_t createdAt;
uint64_t updatedAt;
T(uint64_t c_id, std::string_view c_description, char c_status, uint64_t c_createdAt, uint64_t c_updatedAt) :
id(c_id),
description(c_description),
status(c_status),
createdAt(c_createdAt),
updatedAt(c_updatedAt) {}
T(T&& other) :
id(other.id),
description(std::move(other.description)),
status(other.status),
createdAt(other.createdAt),
updatedAt(other.updatedAt) {}
// member functions
};
At some point, I need to append an optional into a vector. What is the best way between these options (or are there other options)?
std::optional<T> opt = myFunction();
std::vector<T> tasks;
if(opt.has_value()) {
tasks.push_back(*opt);
tasks.push_back(opt.value());
tasks.push_back(std::move(*opt));
tasks.emplace_back(*opt);
tasks.emplace_back(opt.value());
tasks.emplace_back(std::move(*opt));
}
Thave a move constructor? You left out all member functions, including the most important one for this question.Tsymbol name is usually used as template parameter. So when you use this as actual class name this is vary confusing for may developers. You should useFooorBar.