Skip to content
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

Merged
merged 2 commits into from
Jul 10, 2024

Conversation

geijnmh
Copy link

@geijnmh geijnmh commented Jul 7, 2024

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.

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
Comment on lines 86 to 90
#if __cplusplus >= 202002L
consteval key_type generate_key(key_type seed)
#else
constexpr key_type generate_key(key_type seed)
#endif

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
{
    // ...
}

Copy link
Owner

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.

Copy link
Author

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.

@MarioLiebisch
Copy link

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>
Copy link
Owner

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.

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).

Copy link
Author

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.
@adamyaxley adamyaxley changed the title Allow for C++20 standard compiling #44 Allow for C++20 standard compiling Jul 9, 2024
Copy link
Owner

@adamyaxley adamyaxley left a 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.

@geijnmh geijnmh closed this Jul 9, 2024
@geijnmh geijnmh reopened this Jul 9, 2024
@adamyaxley adamyaxley merged commit a46cd5d into adamyaxley:master Jul 10, 2024
8 checks passed
@adamyaxley adamyaxley linked an issue Jul 10, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

C++20 support
3 participants