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

improve: replace type traits with STL #785

Merged
merged 3 commits into from
Jul 2, 2024
Merged

Conversation

ranisalt
Copy link
Contributor

@ranisalt ranisalt commented Jun 12, 2024

Description

Since C++20 is enabled, these type traits are included in the standard library and don't need to be implemented here.

How Has This Been Tested

  • It compiles
  • Test B

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I checked the PR checks reports
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

@ranisalt ranisalt marked this pull request as ready for review June 13, 2024 11:39
@ranisalt
Copy link
Contributor Author

Looks like Windows builds are broken, they're failing even on master

@mehah
Copy link
Owner

mehah commented Jun 13, 2024

Looks like Windows builds are broken, they're failing even on master

we will analyze, but for now we can ignore this error and merge, just set this condition to not compile in MSVC.
thx

@@ -74,7 +72,7 @@ namespace stdext
template<typename... Args>
int snprintf(char* s, size_t maxlen, const char* format, const Args&... args)
{
std::tuple<typename replace_extent<Args>::type...> tuple(args...);
std::tuple<std::decay_t<Args>...> tuple(args...);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1>D:\programacao\jogos\tibia\otclient\src\framework\stdext\format.h(75,48): error C2661: 'std::tuple<int,char *,CHAR *,unsigned __int64,unsigned __int64 >::tuple': no ​​overloaded function takes 5 arguments
1>D:\programacao\jogos\tibia\otclient\src\framework\stdext\format.h(75,48): error C2661: 'std::tuple<int,char *,unsigned __int64>::tuple': no overloaded function takes 3 arguments
1>D:\programacao\jogos\tibia\otclient\src\framework\stdext\format.h(75,48): error C2665: 'std::tuple<char *>::tuple': no ​​overloaded function can convert all types of arguments

possible fix: (put condition to not compile in MSVC)

#ifndef _MSC_VER
    // Improved snprintf that accepts std::string and other types
    template<typename... Args>
    int snprintf(char* s, size_t maxlen, const char* format, const Args&... args)
    {
        std::tuple<std::decay_t<Args>...> tuple(args...);
        return expand_snprintf<std::tuple_size_v<decltype(tuple)>>::call(s, maxlen, format, tuple);
    }

    template<typename... Args>
    int snprintf(char* s, size_t maxlen, const char* format)
    {
        std::strncpy(s, format, maxlen);
        s[maxlen - 1] = 0;
        return strlen(s);
    }
#endif

Copy link
Owner

@mehah mehah Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ranisalt
I did the review and forgot to apply it. 😅

@mehah mehah merged commit 859527a into mehah:main Jul 2, 2024
10 checks passed
@mehah mehah changed the title Replace type traits with STL improve: replace type traits with STL Jul 2, 2024
@mehah
Copy link
Owner

mehah commented Jul 2, 2024

@ranisalt
Unfortunately, after these changes, the modules are showing errors. :S

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.

None yet

2 participants