The type of the vector at line 19 is evaluated at compile time due to decltype, correct? So it doesn't waste time at runtime?
And my second question is how would I even write the render_doodlefunction? I'm at a loss there, should I put some global variable before the function definition? Seems like a bad, confusing practice. Would the compiler be smart enough to know I'm just using some dummy variable to work with decltype?
EDIT: Just tested this
auto, duh... :)
Edit2: Apparently this is only technically allowed in C++14, which isn't a problem, but how would I have done this in only C++11? Would templates be the only option?
Yes, the type is determined at compile time. Templates have to be instantiated at compile time, which is one of the things decltype is useful for.
As for your render_doodle function, there are a couple of ways. Your 'C++14' (not quite, auto only works like that for lambdas) function is the same is this:
As for another way you could do it, the only way I can think of off the top of my head is to put in the actual type of the returning function yourself.
Thanks, I feel like I knew that and have been told it before but still had to be reminded. =) Compilers are amazing to deduce so much stuff at compile time, especially with all that typeid, decltype, and auto stuff.
Oh I just saw your edit about it not being valid C++14 either (I hadn't actually tried to compile it under C++14 yet, had only seen the (apparently wrong) warning about it needing C++14 ;p).
Your type_traits code should do the trick, much appreciated.
Edit: I'll try it out now thankfully I have the time.
If it doesn't work see my edited post.
Yeah I have my "doodle" as an std::vector of all that stuff and it is giving errors when I try to apply that.
But don't worry, I'll just use the template and read up on type_traits later to see if I can resolve it!
Grateful for both of your times.
Edit: @NT3 yeah that does compile!
And yeah it's incredibly long and messy but hey it works.
________________________
And one more thing, just wanted to say I feel kinda dumb because I got lambdas mixed up with function objects - lambdas need auto but function objects don't, so