Hi, I have implemented the following code below on variadic templates for creating exponents of 2 based on c++17 standard, however, my lecturer has thrown in additional constraints and said that I must not use any (*) multiplication operators and (+) addition operators in my code... May I know what I can do to make a change in the line return seq_t<Count_t - 1, 1, 2 * Rest...>(); below such that I am able to generate exponents of 2, without using (*) operator and (+) operator. Note: code should remain the same way if possible. Only change the operators
Yes, but I need to keep the use of meta functions in my program above, its the logic that needs changed, but i'm not sure how...
To be more specific, What can I replace the line return seq_t<Count_t - 1, 1, 2 * Rest...>(); above such that I am able to generate exponents of 2 but note that I can't use the (*) and (+) operators. And keeping the rest of the program intact as that is one of the requirements.
I tried doing this:
return seq_t<Count_t - 1, 1, 1<<(Rest)...>(); but doesn't work.
Well, the assignment is about parameter packs & sequence types . It will need to generate/ create sequence , then extract sequences from the types & then display them . It must generate powers of 2. I have done all that, but only can't figure out the problem as stated above.
It says the above? I re-worded very little. "The assignment is about parameter packs & sequence types. It will need to generate/ create sequence , then extract sequences from the types . It must generate powers of 2. It must not contain any (*) multiplication or (+) addition operators"
The code I posted above, I followed my professor's code sample, and modify it to make it generate the sequence of powers of 2. However, Now he said it can't contain any * operators and + operators. He said we MUST follow his style.
Thanks for your help mbozzi. Oh man, I was quite close. This is a little confusing. Just to clarify, what you are doing is left shifting the bit first, then unpack the arguments right? I agree with you though. I hate the restrictions he imposes. Its very unnecessary. But what am I to do. Anyway, now, how do I eliminate the (+) operator within Count_t + 1 as shown below, what can I replace it with, whilst still keeping the program intact. Because as he said he doesn't allow for * operator and + operator. If only it wasn't variadic templates.. it would be much easier... Not intuitive enough for me as I am new to this.
1 2
template <size_t Count_t>
using type_m = decltype(seq_t<Count_t + 1>());
Hi mbozzi, thanks for the reply! I can't just erase the + operator, otherwise my output would be 1 number short. After I erased, the print out stopped at 4611686018427387904 instead of 9223372036854775808. I need to print the latter as well, to match my lecturer's test case. Are there any other ways to go about handling this? Hope you can help. Thank you.
With regards to the standard library, my lecturer wants us to use those function definitions that you see above for the assignment; It's not a case whereby I do not want to be more efficient or anything. So I am limited in that sense.