From a4d0f2013d4ea0c9290c99b4a756c94da0800f51 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 29 Jan 2025 12:20:27 +0100 Subject: [PATCH] Add a std::span implementation for old platforms --- .gitmodules | 6 ++++++ include/lol/3rdparty/span | 1 + include/lol/std/span | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 160000 include/lol/3rdparty/span create mode 100644 include/lol/std/span diff --git a/.gitmodules b/.gitmodules index 7c726ab1..4be492fa 100644 --- a/.gitmodules +++ b/.gitmodules @@ -38,6 +38,12 @@ branch = master update = checkout +[submodule "span"] + path = include/lol/3rdparty/span + url = https://github.com/tcbrindle/span + branch = master + update = checkout + [submodule "doctest"] path = include/lol/3rdparty/doctest url = https://github.com/doctest/doctest diff --git a/include/lol/3rdparty/span b/include/lol/3rdparty/span new file mode 160000 index 00000000..836dc6a0 --- /dev/null +++ b/include/lol/3rdparty/span @@ -0,0 +1 @@ +Subproject commit 836dc6a0efd9849cb194e88e4aa2387436bb079b diff --git a/include/lol/std/span b/include/lol/std/span new file mode 100644 index 00000000..e677a5df --- /dev/null +++ b/include/lol/std/span @@ -0,0 +1,37 @@ +// +// Lol Engine +// +// Copyright © 2010–2025 Sam Hocevar +// +// Lol Engine is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. +// + +#pragma once + +// Assume std::span is available, then check for exceptions +#define LOL_HAS_STD_SPAN 1 + +#if !defined __SCE__ +# include // Provide __cpp_lib_span if relevant +# if !defined __cpp_lib_span +# undef LOL_HAS_STD_SPAN +# endif +#endif + +#if defined __SCE__ // SCE platforms do not have , so check for C++20 support +# if !_HAS_CXX20 +# undef LOL_HAS_STD_SPAN +# endif +#endif + +// Include if everything went well, otherwise use the 3rd party implementation +#if defined LOL_HAS_STD_SPAN +# include +#else +# define TCB_SPAN_NAMESPACE_NAME std +# include "../3rdparty/span/include/tcb/span.hpp" +#endif