Комментарии:
the only true compile-time optimization is performed with meta-template-programming
constexpr std::string in its current form is utter useless garbage
also I don't see it in this video at all
What on earth is happening with people's speech?! Exshtremely? Do you also say conshtexpression?
ОтветитьThis video title promised constexpr std::string usage. Did I miss it?
ОтветитьCompile time/runtime reminds me of Forth. A beautifully simple 'close to the metal' programming language based on stacks and RPN. +1
ОтветитьCan you write the Ackermann function as a constexpr? :-)
ОтветитьCouldn't you have an auto return type and return a std::array constructed in the get_vector function?
ОтветитьHow can you remove the whole bool use_vector parameter with one keystroke? Is it an out of the box VS feature?
ОтветитьHello, what is your visual studio theme
ОтветитьI sort of thought we would be allowed to make empty vectors ve constexpr. The use case I thought about was doing loookup and returning a reference to a vector, but if no element is found, you can still return a reference to a statically allocated vector. You sort of also want that created at compile time, because you should know what a const empty vector looks like at compile time.
However, I guess std::span is going to fulfil that role even better.
I want a constexpr program.
It accepts no input and gives no output.
It does not change state in any way whatsoever.
It runs for a while, does nothing, then terminates.
And want an alternative version that does not terminate.
These are useful programs.
This is great but why is no one worried about compile times being increased in the process when using stuff like this? I can imagine in big projects the compile times already are long and then you add this on top. How much the compile time would be increased in percentage if you have to evaluate much more code in compile time every time you are developing a big application?
ОтветитьDoes this mean that we can get a compile time segmentation faults 😂
Ответитьtoo nice!
ОтветитьCalling begin() and end() without std:: sort of blows my mind. :O I'm not used to seeing argument-dependent lookup except in operators.
ОтветитьI guess that vectors are going to be returnable in the far future. The contents might be stored to static memory and when there was a call to the function, a real vector with heap memory is created in the similar way like from an initializer list
ОтветитьFor the get_vector().size(); failure, could it be the case that to be able to call size() the compiler is creating a temporary instance of std::vector<int> and that is being seen as an instance of moving compile time allocated memory to the runtime world, leading to that particular failure?
ОтветитьThis compile-time runtime duality made me reminisce about boost fusion... ah that was so much fun....
ОтветитьWhy not use `constexpr auto vector = get_vector()` in constexpr function? then you could use size for array arg.
ОтветитьWhen VS 2019 16.10 Preview 3 will be released you can test std::format. Or earlier if you have time to compile Microsoft stl from github.
ОтветитьInteresting, potentially very powerful and useful and of course overly complicated and counter-intuitive to use... C++ never really changes it only gets more C++! Seriously though do you think that in the future standards we could see some kind of automatic memory context management when it comes to compile / runtime sharing? It's obviously possible as you've just shown, just that your compile time results are dependent on another compile time expression.. it's almost like we need another level of pre-compile time computation to compute the order of the compile time expressions..!?
Ответитьtemplate <typename T>
auto constexpr array_from_vector(vector<T> const &v) {
return ::std::array<T, v.size()>{v.begin(), v.end()};
}
Why not just get rid of of the template parameter size, and on line 25 just use std::array<int, vector.size()> result{}; isnt that the same thing just everything is happy in constexpr land?
ОтветитьWill we eventually see a compile time debugger with breakpoints, step, next etc?
ОтветитьWhy do you use auto keyword for every function? Is it modified in compile time?
ОтветитьIs someone already making a compile-time compiler?
Ответить