#single Template class object for set/get function for user defined datatypes

6 messages · Page 1 of 1 (latest)

vestal salmon
#

I have one class which has a set and get function for 5 structures. i want to maintain a single class with function template.

smoky shaleBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

gleaming lark
#

post code

wintry drum
#

You could take a template and then do a constexpr if-else and only allow inputs of the specific structures by throwing an error using staticassert if the input isnt of the allowed types. By using this only the get/set part of the method for the input datatype will be executed since the compiler evaluates the constexpr statements at compile time.

#

Look at std::is_same_v for comparing types.

smoky shaleBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.