I would like it that bitsets would throw an error if they are assigned a value outside of their bitrange. Currently the standard implementation just uses modular arrithmatic to assign the value of 0001 to bitset<4> a(16);
could I do something like
1 2 3 4 5 6
#define old_assignment_operator(size, name, param) bitset<size> #name (param)
#define bitset<size> /*ok I really don't know how to do this, but I want to hide
the standard declarator for bitset<any_size>. How would I do that? */ /
/*check for compliance, if failure: cerr << "Sorry out of range error.\n" << endl;*/ /
old_assignment_operator(/*yada yada yada*/)
//end of macro.
I'm not sure I follow what you're trying to do, but...
You can't use macros to overload / change behavior of the assignment operator. The only thing macros do is substitute a block of code into an identifier. However that identifier can't have symbols (like an operator).
I want to hide the standard declarator for bitset<any_size>
It's a public interface. The only way to hide it would be to not #include the interface.
I would like to have a macro that takes as a paramter an unsigned int, but instead of needing to enclose the parameter within () to have them enclosed within <>.
That way I would be able to with a single couple lines of code replace all instances of bitsets into an implementation that is more robust, say, by giving an error message if you were to try to force the number 16 into a bitset<4>, which only has enough bits to represent the numbers 0 - 15. etc etc etc
The preprocessor can do this in the same way that the compiler can let you make a function call by passing actual parameters using template syntax (a_function<a_run_time_value>;). Which is to say, not at all.
Sounds like what you want is to wrap std::bitset with your own templated class. Then you can make whatever checks you want before calling the problematic functions.
The preprocessor can dothis in the same way that the compiler can let you make a function call by passing actual parameters usingtemplate syntax (a_function<a_run_time_value>;). Which is to say, not at all.