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

Consider updating Overload C++ version from 17 to 20 #294

Open
adriengivry opened this issue Dec 12, 2023 · 1 comment · May be fixed by #311
Open

Consider updating Overload C++ version from 17 to 20 #294

adriengivry opened this issue Dec 12, 2023 · 1 comment · May be fixed by #311
Labels
Feature New feature to the engine Optimization Optimization related stuff

Comments

@adriengivry
Copy link
Owner

adriengivry commented Dec 12, 2023

Now that C++20 is widely available and support, we should consider updating Overload to take advantage of it.
Some features we could use from C++20:

Feature Use case
std::string::ends_with and std::string::starts_with Checking file extension
likely and unlikely attributes Flag unlikely paths, with component updates for instance
Map/Set contains We use std::map and std::set in some places, and we could use this feature
Designated initializers To initialize descriptors with specific values
consteval Could be used to generate default values (identity matrix...)
Concept Could be used for our component-based implementations (derived_from, convertible_to...)
Synchronized buffered outputstream Could be used to make moving our logging system to another thread easier
std::span Could make some of our functions more generic/work with more collection types
Bit operations Would simplify some of our pipeline state operations and enum flags
Math constants So we don't have to define pi and euler's number
Heap allocated arrays with smart pointer i.e. std::make_shared<int[]>(5)
std::bit_cast Safer way to reinterpret an object from one type to another
Bit-field initializers Could simplify the initialization of default values for structs like PipelineState
erase_if Instead of using remove_if + erase, it would simplify a bunch of our code
source_location::current() Instead of __LINE__ and __FILE__, to trace assert locations
std::bind_front Instead of using std::bind with std::placeholder::_1 (shorter syntax)
std::lerp Could be used in OvMaths and might be better vectorized

... and more!

@adriengivry adriengivry added Feature New feature to the engine Optimization Optimization related stuff labels Dec 12, 2023
@adriengivry
Copy link
Owner Author

adriengivry commented Dec 12, 2023

After some investigation, it looks like C++20 introduces some regressions, notably this one:
https://developercommunity.visualstudio.com/t/static-assert-failing-with-cppunittestassert-after/1643134

In our IniFile.inl we have:

if constexpr (...)
{
}
else
{
    static_assert(false, "...");
}

This doesn't compile with C++20 while it should.

This shouldn't prevent us from updating, as this issue could be mitigated, by using concepts for instance:

Concept declaration:

template<class T>
concept IniType =
	std::is_same<bool, T>::value ||
	std::is_same<std::string, T>::value ||
	std::is_integral<T>::value ||
	std::is_floating_point<T>::value;

Usage:

template<IniType T>
T Get(const std::string& p_key);

template<IniType T>
T GetOrDefault(const std::string& p_key, T p_default);

template<IniType T>
bool Set(const std::string& p_key, const T& p_value);

template<IniType T>
bool Add(const std::string& p_key, const T& p_value);

@adriengivry adriengivry linked a pull request Nov 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature to the engine Optimization Optimization related stuff
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant