Modern C++ Visual Assist Script for Encapsulating object with fail safe mechanism

This is a small snippet for Visual Assist to encapsulate member objects and making sure that you can not use those objects unless they are instantiated or assigned. Also making sure that assignment operation is type safe.:

$end$$SymbolType$ $GeneratedPropertyName$() const {
if (this->$SymbolName$ == nullptr)
throw std::bad_function_call(“The object you are trying to use is empty. This functionality is not avaible. Please pass an object before usage.”);

return $SymbolName$;
}
template<typename T>
void $GeneratedPropertyName$(T &&value) {

static_assert(!is_same<objectPhysics, T>::value, Aurora::Errors::ErrorMessages::TypeMismatch.c_str());

$SymbolName$ = std::forward<T>(value); }

 

Or with assertion on both operations(for minimal overhead for release version):

$end$$SymbolType$ $GeneratedPropertyName$() const {
assert($SymbolName$ == nullptr && “The object you are trying to use is empty. This functionality is not available. Please pass an object before usage.”);

return $SymbolName$;
}
template<typename T>
void $GeneratedPropertyName$(T &&value) {
static_assert(!is_same<objectPhysics, T>::value, Aurora::Errors::ErrorMessages::TypeMismatch.c_str());

$SymbolName$ = std::forward<T>(value);
}