-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#44 Allow for C++20 standard compiling #45
Conversation
C++20 standard introduces std::remove_cvref<T>, which allows for a reduction of obfuscator code. C++20 allows for consteval expressions which force the compiler to only accept compile-time evaluation of functions. This is especially useful for obfuscating purposes.
obfuscate.h
Outdated
#if __cplusplus >= 202002L | ||
consteval key_type generate_key(key_type seed) | ||
#else | ||
constexpr key_type generate_key(key_type seed) | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd avoid this kind of branching all over the place. Instead, define a macro like _AY_CONST
or similar and then use this instead.
#if __cplusplus >= 202002L
#define _AY_CONST consteval
#else
#define _AY_CONST constexpr
#endif
_AY_CONST key_type generate_key(key_type seed)
{
// ...
}
_AY_CONST size_type size() const
{
// ...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this!
I agree, but would probably give it a more explicit name like AY_CONSTEVAL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that will make the code a cleaner. Will update it.
Great you figured it out.👍 |
obfuscate.h
Outdated
@@ -28,6 +28,9 @@ std::cout << obfuscated_string << std::endl; | |||
----------------------------------------------------------------------------- */ | |||
|
|||
#pragma once | |||
#if __cplusplus >= 202002L | |||
#include <type_traits> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces a dependency on the standard library, which is something that not all users may want or are able to do.
Since we don't get anything extra except for cleaner code, I think we should not go down this route and keep the library a zero dependency library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't think about this, but you're right. Plus the code doesn't really get shorter/cleaner since the fallback code is there anyway (and in the end it's probably implemented very similar or even identical).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I will remove it if you do not want to use the STL.
* Use macro to use consteval when compiling in C++20 standard, or constexpr for C++14/17. Only for those functions which require compile-time evaluation. * Keep STL independent, because not all users may be willing or able to use the STL in their environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good to merge to me.
C++20 standard introduces std::remove_cvref, which allows for a reduction of obfuscator code. C++20 allows for consteval expressions which force the compiler to only accept compile-time evaluation of functions. This is especially useful for obfuscating purposes.
The compiler directives create a bit of clutter, but this way it is compatible with C++14 / C++17 settings.
I upload this in the hope it is useful. I welcome any feedback for further improvement.