Consider message::reset
- Dominant language
- C++
- Stars
- 4.8k
- Forks
- 694
- Avg merge
- 12h 48m
- Merged PRs (30d)
- 1
Description
This function could be used in the message-oriented `read` overloads to clear the message before use, eliminating a common class of user errors.
The signature could accept a variable argument list, with this implementation:
```
template
template
void
message::
reset(Args&&... args)
{
// This means you are trying to call reset() on a message that is not default constructible
static_assert(sizeof...(args)>0 || std::is_default_constructible::value,
"DefaultConstructible requirements not met");
// This means you did not pass the correct parameters to construct a message
static_assert(sizeof...(args)==0 || std::is_constructible::value,
"Constructor argument list mismatch");
// reset may only be used on messages that are MoveAssignable
static_assert(std::is_move_assignable::value,
"MoveAssignable requirements not met");
message m(std::forward(args...));
*this = std::move(m);
}
```
The `read` overloads would need to be modified to require messages that are **DefaultConstructible**, or changed to accept a list of constructor arguments.
Contributor guide
Assessment
This issue has not been assessed yet.