Closed niXman closed 6 years ago
I believe this is needed. If you use __FILE__
and __LINE__
directly in the function it will print better_assert.hpp
as fine and the line of the cerr
call. Try it yourself if you dont believe it :)
Anyway it is passed as reference and it is referring to a compiler defined value which is probably const static. So it should not allocate anything :)
I think this also applies to the message
object.
Can you provide an example?
Anyway it is passed as reference and it is referring to a compiler defined value which is probably const static. So it should not allocate anything :)
You're wrong.
The two temporary objects will be created here that allocate memory on the heap and copy the static const char [N]
arrays.
Okay, that is true. Can you provide an example to avoid it?
Yes, I should have said in C++style :)
I can change it for file
and condition
, will not change it for message
as it might be the case that someone passes an actual string.
Moreover, the file
and line
you can be put in one static const char[]
array: https://wandbox.org/permlink/OfHVWipSg1sSKMgV
I can change it for file and condition, will not change it for message as it might be the case that someone passes an actual string.
Or maybe the user of your code will always be hardcoding messages? ;) But your code in this case will always create a temporary object ;)
In C++ it is considered a bad form to "pay" for what you do not use. I mean the creation of a temporary object and the memory allocation in the heap.
In C++ it is considered a bad form to "pay" for what you do not use. I mean the creation of a temporary object and the memory allocation in the heap. You might want to reuse the same message among multiple asserts. So it makes sense to allocate a single string and pass it around.
I can have two overloads...
I like this one, a single #define _STRINGIZE(x) #x
should be enough...
EDIT: no is not
Added your suggestions. Thanks a lot! Also I have done the overload for char*/string&.
Appreciated your help!
But, what's this?: std::cerr << "oooooooo" << std::endl;
;)
In line 33.
Oh sh*t :)
Hi,
There is no need to create the two temporary
file
andcondition
objects that, moreover, allocates memory in the heap: https://github.com/amallia/better_assert/blob/c5e3033a9b17e27401094e13ee93037f94f9d639/include/better_assert/better_assert.hpp#L19