diff --git a/Makefile b/Makefile index 3a44adb..5a0e04c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -OSTD_CXXFLAGS = -O2 -g -std=c++14 -Wall -Wextra -Wshadow -Wold-style-cast -I. +OSTD_CXXFLAGS = -O2 -g -std=c++1z -Wall -Wextra -Wshadow -Wold-style-cast -I. EXAMPLES_OBJ = \ examples/format \ diff --git a/README.md b/README.md index 3812920..a1a0990 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # octastd -OctaSTD is an extension of the C++14 standard library which mainly provides +OctaSTD is an extension of the C++17 standard library which mainly provides ranges (to replace iterators) but also various other utilities like proper streams, string formatting, concurrency utilities and others. It's meant to replace the more poorly designed parts of the C++ standard library to @@ -8,42 +8,45 @@ make the language easier and more convenient to use. Documentation for OctaSTD can be found at https://wiki.octaforge.org/docs/octastd. -Full C++14 support is required in your compiler. +It's not necessary that your compiler fully supports C++17, only C++14 +language is used, but new C++17 containers have to be present, such as +`string_view` and `optional`. ## Supported compilers Compiler | Version -------- | ------- -gcc/g++ | 5.4+, 6+ -clang | 3.8+ (most platforms including LLVM for macOS), 8.0.0+ (macOS Xcode) +gcc/g++ | 7+ +clang | 4+ -Other C++14 compliant compilers might work as well. OctaSTD does not utilize -compiler specific extensions. - -While Clang 3.6 does implement a sufficient level of C++14 support, it suffers -from a bug in its variable template implementation that prevents OctaSTD from -functioning. Therefore version 3.8 or higher is necessary (where this bug was -finally fixed). - -GCC has implemented a sufficient feature level of C++14 since version 5.1, but -also is too buggy until version 5.4. Version 5.1 and 5.2 have variable template -partial specialization issues and version 5.3 has an internal compiler error -triggered by the tuple implementation. Version 5.4 appears to be the first one -to compile this without issues. GCC 6.1 also appears to compile without problems. +You need those mainly to get the right standard library version (libstdc++ +or libc++). Other compilers might work as well, as long as the necessary +standard library features are supplied. MSVC++ is unsupported and for the time being will remain unsupported. As of MS Visual Studio 2017 RC, basic C++11 features are still broken and prevent usage of the library, with no reasonable workarounds. I will be testing new versions as they get released and mark it supported as soon as it actually works, but no active effort will be put towards making it work. On Windows, you're free to -use GCC/Clang or if you need the Visual Studio environment, the Visual Studio -version of Clang with MS Codegen should work just fine. +use GCC/Clang, if you need Visual Studio, LLVM integration exists. + +## Why is C++17 necessary? + +Sadly, it's not possible to properly integrate `std::string` and `std::hash` +with OctaSTD ranges without utilizing `std::string_view`. Also, C++17 provides +library features that OctaSTD would have to implement otherwise, which would +lead to potentially incompatible APIs. However, OctaSTD does not make wide +use of C++17 language features, limiting itself mostly to library features +which have been present for more or less a pretty long time (in experimental +namespace for example) which should avoid buggy behavior. There is still the +problem of requiring a very recent toolchain, but this situation should solve +itself in near future. ## Supported operating systems -Most of OctaSTD is entirely platform independent and relies only on the standard -library. Therefore it can be used on any operating system that provides a C++14 -compiler and library implementation. +Most of OctaSTD is entirely platform independent and relies only on the +standard library. Therefore it can be used on any operating system that +provides the right toolchain. There are certain parts (currently the filesystem module) that however do rely on system specific APIs. These are restricted to POSIX compliant operating diff --git a/ostd/string.hh b/ostd/string.hh index d2b1fdc..a6ff989 100644 --- a/ostd/string.hh +++ b/ostd/string.hh @@ -10,6 +10,9 @@ #include #include +#include +#include + #include "ostd/utility.hh" #include "ostd/range.hh" #include "ostd/vector.hh" @@ -208,6 +211,11 @@ diffsize: return c; } + /* that way we can assign, append etc to std::string */ + operator std::basic_string_view>() const { + return std::basic_string_view>{data(), size()}; + } + private: T *p_beg, *p_end; }; @@ -246,6 +254,20 @@ inline bool starts_with(ConstCharRange a, ConstCharRange b) { return a.slice(0, b.size()) == b; } +template +struct ranged_traits> { + static CharRangeBase iter(std::basic_string &v) { + return CharRangeBase{v.data(), v.size()}; + } +}; + +template +struct ranged_traits const> { + static CharRangeBase iter(std::basic_string const &v) { + return CharRangeBase{v.data(), v.size()}; + } +}; + template class StringBase { using StrPair = detail::CompressedPair, A>; @@ -951,6 +973,15 @@ struct ToString { } }; +template<> +struct ToString { + using Argument = std::string; + using Result = String; + String operator()(Argument const &s) { + return iter(s); + } +}; + template<> struct ToString { using Argument = CharRange; @@ -1124,4 +1155,22 @@ inline TempCString to_temp_cstr( } /* namespace ostd */ +namespace std { + +template<> +struct hash { + size_t operator()(ostd::CharRange const &v) { + return hash{}(v); + } +}; + +template<> +struct hash { + size_t operator()(ostd::CharRange const &v) { + return hash{}(v); + } +}; + +} + #endif diff --git a/test_runner.cc b/test_runner.cc index d18cd57..7f4345b 100644 --- a/test_runner.cc +++ b/test_runner.cc @@ -25,7 +25,7 @@ int main() { /* configurable section */ auto compiler = env_get("CXX").value_or("c++"); - auto cxxflags = "-std=c++14 -I. -Wall -Wextra -Wshadow -Wold-style-cast " + auto cxxflags = "-std=c++1z -I. -Wall -Wextra -Wshadow -Wold-style-cast " "-Wno-missing-braces"; /* clang false positive */ auto testdir = env_get("TESTDIR").value_or("tests"); auto srcext = ".cc";