├── examples ├── basics │ ├── _data │ │ ├── norwegian_russian_name.txt │ │ └── norwegian_russian_name.utf-16.txt │ ├── list_text │ │ ├── international.txt │ │ └── list.textbook-version.cpp │ ├── personalized_greeting │ │ ├── norwegian_russian_name.txt │ │ ├── norwegian_russian_name.utf-16.txt │ │ ├── greeting.textbook_version.cpp │ │ ├── greeting.cpp │ │ └── greeting.wide_text_version.cpp │ ├── hello_world │ │ ├── hello_world.cpp │ │ └── international_hello_world.cpp │ ├── ungood_encoding │ │ ├── ungood_encoding.latin-1.cpp │ │ ├── ungood_encoding.utf-8_sans_bom.cpp │ │ └── .vscode │ │ │ └── launch.json │ └── command_line_arguments │ │ ├── command_line_arguments.textbook.cpp │ │ ├── command_line_arguments.cpp │ │ └── command_line_arguments.most_portable.cpp ├── fixes │ ├── data │ │ ├── norwegian_russian_name.txt │ │ └── norwegian_russian_name.utf-16.txt │ ├── math_constants.cpp │ ├── output_of_implicit_wide_cstring.cpp │ ├── randomly_random.cpp │ ├── console_io.cpp │ ├── s_literal_operator.cpp │ ├── alternative_keywords.cpp │ ├── native_locale_as_default.cpp │ └── ansi_escape_sequences.cpp └── c++17 │ ├── filesystem.cpp │ └── string_view.cpp ├── images ├── pooh.jpg ├── icon │ ├── stdlib-icon.png │ ├── stdlib-icon.25-pct.png │ ├── stdlib-icon.50-pct.png │ ├── wrapped-stdlib-icon.png │ ├── wrapped-stdlib-icon.25-pct.png │ ├── wrapped-stdlib-icon.50-pct.png │ ├── wrapped-stdlib-icon - 1.svg │ └── wrapped-stdlib-icon.svg ├── international_hello_world.png ├── personalized_greeting.take_1.png ├── personalized_greeting.take_2.png ├── international_hello_world.colorized.png ├── personalized_greeting.take_1.colorized.png ├── personalized_greeting.take_2.colorized.png ├── personalized_greeting.take_1.colorized.annotated.png └── personalized_greeting.take_2.colorized.annotated.png ├── .gitignore ├── source ├── all │ ├── localization.hpp │ ├── fixes.hpp │ ├── text │ │ ├── c_localization.hpp │ │ ├── cpp_localization.hpp │ │ ├── cpp_strings.hpp │ │ └── c_strings.hpp │ ├── text.hpp │ ├── numerics │ │ ├── number_range_limits.hpp │ │ └── integer_types.hpp │ ├── of_sublibrary │ │ ├── iterators.hpp │ │ ├── atomic_operations.hpp │ │ ├── algorithms.hpp │ │ ├── regular_expressions.hpp │ │ ├── localization.hpp │ │ ├── diagnostics.hpp │ │ ├── thread_support.hpp │ │ ├── strings.hpp │ │ ├── numerics.hpp │ │ ├── containers.hpp │ │ ├── input_output.hpp │ │ ├── general_utilities.hpp │ │ └── language_support.hpp │ ├── non_io_fixes.hpp │ ├── ppp_facilities.unqualified.hpp │ ├── basics.hpp │ ├── numerics.hpp │ ├── io.hpp │ └── ppp_facilities.hpp ├── fix │ ├── gcc_random_device.hpp │ ├── console_io.hpp │ ├── default_locale.hpp │ ├── msvc_named_boolean_operators.hpp │ ├── msvc_utf8_literals.hpp │ ├── msvc_wolfcalls_about_std_functions.hpp │ ├── default_c_locale.hpp │ ├── output_of_implicit_wide_c_string.hpp │ ├── default_cpp_locale.hpp │ └── math_constants_availability.hpp ├── list.hpp ├── map.hpp ├── set.hpp ├── array.hpp ├── chrono.hpp ├── complex.hpp ├── deque.hpp ├── locale.hpp ├── streambuf.hpp ├── tuple.hpp ├── vector.hpp ├── atomic.hpp ├── bitset.hpp ├── forward_declarations │ └── fwd_iostreams.hpp ├── iterator.hpp ├── mutex.hpp ├── stack.hpp ├── typeindex.hpp ├── codecvt.hpp ├── exception.hpp ├── ratio.hpp ├── future.hpp ├── new.hpp ├── thread.hpp ├── typeinfo.hpp ├── algorithm.hpp ├── c │ ├── time.hpp │ ├── float.hpp │ ├── limits.hpp │ ├── locale.hpp │ ├── stdio.hpp │ ├── errno.hpp │ ├── fenv.hpp │ ├── stdarg.hpp │ ├── stdint.hpp │ ├── uchar.hpp │ ├── string.hpp │ ├── wchar.hpp │ ├── signal.hpp │ ├── iso646.h │ ├── stddef.hpp │ ├── setjmp.hpp │ ├── assert.hpp │ ├── complex.h │ ├── inttypes.hpp │ ├── stdbool.hpp │ ├── ctype.hpp │ ├── wctype.hpp │ ├── stdlib.hpp │ ├── stdalign.hpp │ ├── tgmath.hpp │ └── math.hpp ├── forward_list.hpp ├── type_traits.hpp ├── istream.hpp ├── queue.hpp ├── scoped_allocator.hpp ├── shared_mutex.hpp ├── stdexcept.hpp ├── unordered_map.hpp ├── unordered_set.hpp ├── utility.hpp ├── condition_variable.hpp ├── iomanip.hpp ├── memory.hpp ├── valarray.hpp ├── initializer_list.hpp ├── numeric.hpp ├── iostream.hpp ├── regex.hpp ├── functional.hpp ├── ioswfd.hpp ├── system_error.hpp ├── limits.hpp ├── random.hpp ├── ios.hpp ├── ostream.hpp ├── fstream.hpp ├── sstream.hpp ├── _impl │ ├── converter_buffer_size.hpp │ ├── custom_process_command_line.hpp │ ├── windows_console_io │ │ ├── constants.hpp │ │ ├── Wide_console_input_buffer.hpp │ │ ├── api.hpp │ │ ├── apiwrap.hpp │ │ ├── Byte_console_input_buffer.hpp │ │ └── Console_output_buffer_.hpp │ ├── winapi_types.hpp │ ├── winapi_constants.hpp │ ├── windows_process_command_line │ │ ├── api.hpp │ │ └── apiwrap.hpp │ ├── windows_char_path │ │ ├── apiwrap.hpp │ │ └── api.hpp │ ├── general_char_path.hpp │ ├── windows_process_command_line.hpp │ ├── linux_process_command_line.hpp │ ├── windows_console_io.hpp │ └── windows_char_path.hpp ├── string.hpp ├── extension │ ├── STDLIB_NORETURN.hpp │ ├── size_types.hpp │ ├── Byte_order.hpp │ ├── char_path.hpp │ ├── Codecvt.hpp │ ├── STDLIB_SYSTEM_BYTE_ORDER.hpp │ ├── hopefully_and_fail.hpp │ ├── version.hpp │ ├── process_command_line.hpp │ ├── char_path.declarations.hpp │ ├── math_constants.hpp │ ├── size_functions.hpp │ ├── utf8_conversion.hpp │ ├── ascii.hpp │ ├── process_command_line.declarations.hpp │ ├── type_builders.hpp │ ├── Streaming_byte_to_wide_converter.hpp │ └── Streaming_wide_to_byte_converter.hpp ├── optional.hpp ├── variant.hpp ├── string_view.hpp └── filesystem.hpp └── .gitattributes /examples/basics/_data/norwegian_russian_name.txt: -------------------------------------------------------------------------------- 1 | Pål Аркадий Jørgen Sæther 2 | -------------------------------------------------------------------------------- /examples/fixes/data/norwegian_russian_name.txt: -------------------------------------------------------------------------------- 1 | Pål Аркадий Jørgen Sæther 2 | -------------------------------------------------------------------------------- /examples/basics/list_text/international.txt: -------------------------------------------------------------------------------- 1 | Every 日本国 кошка likes Norwegian blåbærsyltetøy. 2 | -------------------------------------------------------------------------------- /examples/basics/personalized_greeting/norwegian_russian_name.txt: -------------------------------------------------------------------------------- 1 | Pål Аркадий Jørgen Sæther 2 | -------------------------------------------------------------------------------- /images/pooh.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alf-p-steinbach/Wrapped-stdlib/HEAD/images/pooh.jpg -------------------------------------------------------------------------------- /images/icon/stdlib-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alf-p-steinbach/Wrapped-stdlib/HEAD/images/icon/stdlib-icon.png -------------------------------------------------------------------------------- /images/icon/stdlib-icon.25-pct.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alf-p-steinbach/Wrapped-stdlib/HEAD/images/icon/stdlib-icon.25-pct.png -------------------------------------------------------------------------------- /images/icon/stdlib-icon.50-pct.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alf-p-steinbach/Wrapped-stdlib/HEAD/images/icon/stdlib-icon.50-pct.png -------------------------------------------------------------------------------- /images/icon/wrapped-stdlib-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alf-p-steinbach/Wrapped-stdlib/HEAD/images/icon/wrapped-stdlib-icon.png -------------------------------------------------------------------------------- /images/international_hello_world.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alf-p-steinbach/Wrapped-stdlib/HEAD/images/international_hello_world.png -------------------------------------------------------------------------------- /images/personalized_greeting.take_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alf-p-steinbach/Wrapped-stdlib/HEAD/images/personalized_greeting.take_1.png -------------------------------------------------------------------------------- /images/personalized_greeting.take_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alf-p-steinbach/Wrapped-stdlib/HEAD/images/personalized_greeting.take_2.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.exe 2 | *.obj 3 | *.out 4 | explore_issues 5 | writings 6 | examples/basics/personalized_greeting/greeting.py 7 | build/vs 2017/* 8 | 9 | -------------------------------------------------------------------------------- /images/icon/wrapped-stdlib-icon.25-pct.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alf-p-steinbach/Wrapped-stdlib/HEAD/images/icon/wrapped-stdlib-icon.25-pct.png -------------------------------------------------------------------------------- /images/icon/wrapped-stdlib-icon.50-pct.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alf-p-steinbach/Wrapped-stdlib/HEAD/images/icon/wrapped-stdlib-icon.50-pct.png -------------------------------------------------------------------------------- /images/international_hello_world.colorized.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alf-p-steinbach/Wrapped-stdlib/HEAD/images/international_hello_world.colorized.png -------------------------------------------------------------------------------- /images/personalized_greeting.take_1.colorized.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alf-p-steinbach/Wrapped-stdlib/HEAD/images/personalized_greeting.take_1.colorized.png -------------------------------------------------------------------------------- /images/personalized_greeting.take_2.colorized.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alf-p-steinbach/Wrapped-stdlib/HEAD/images/personalized_greeting.take_2.colorized.png -------------------------------------------------------------------------------- /examples/fixes/data/norwegian_russian_name.utf-16.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alf-p-steinbach/Wrapped-stdlib/HEAD/examples/fixes/data/norwegian_russian_name.utf-16.txt -------------------------------------------------------------------------------- /examples/basics/_data/norwegian_russian_name.utf-16.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alf-p-steinbach/Wrapped-stdlib/HEAD/examples/basics/_data/norwegian_russian_name.utf-16.txt -------------------------------------------------------------------------------- /examples/basics/hello_world/hello_world.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | auto main() -> int 5 | { 6 | cout << "Hello, world!" << endl; 7 | } 8 | -------------------------------------------------------------------------------- /examples/basics/ungood_encoding/ungood_encoding.latin-1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alf-p-steinbach/Wrapped-stdlib/HEAD/examples/basics/ungood_encoding/ungood_encoding.latin-1.cpp -------------------------------------------------------------------------------- /images/personalized_greeting.take_1.colorized.annotated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alf-p-steinbach/Wrapped-stdlib/HEAD/images/personalized_greeting.take_1.colorized.annotated.png -------------------------------------------------------------------------------- /images/personalized_greeting.take_2.colorized.annotated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alf-p-steinbach/Wrapped-stdlib/HEAD/images/personalized_greeting.take_2.colorized.annotated.png -------------------------------------------------------------------------------- /examples/basics/personalized_greeting/norwegian_russian_name.utf-16.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alf-p-steinbach/Wrapped-stdlib/HEAD/examples/basics/personalized_greeting/norwegian_russian_name.utf-16.txt -------------------------------------------------------------------------------- /examples/basics/list_text/list.textbook-version.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | auto main() -> int 6 | { 7 | string line; 8 | while( getline( cin, line ) ) 9 | { 10 | cout << line << endl; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /source/all/localization.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include 6 | #include 7 | -------------------------------------------------------------------------------- /source/all/fixes.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include 6 | #include 7 | #include 8 | -------------------------------------------------------------------------------- /examples/basics/hello_world/international_hello_world.cpp: -------------------------------------------------------------------------------- 1 | // Source encoding: utf-8 with BOM ∩ 2 | #include 3 | using namespace std; 4 | 5 | auto main() -> int 6 | { 7 | cout << u8"Every 日本国 кошка likes Norwegian blåbærsyltetøy.\n"; 8 | cout << "I said, every 日本国 кошка likes Norwegian blåbærsyltetøy.\n"; 9 | } 10 | -------------------------------------------------------------------------------- /examples/basics/personalized_greeting/greeting.textbook_version.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | auto main() 6 | -> int 7 | { 8 | cout << "Hi, what's your name? "; 9 | string name; 10 | getline( cin, name ); 11 | cout << "Pleased to meet you, " << name << "!" << endl; 12 | } 13 | -------------------------------------------------------------------------------- /source/fix/gcc_random_device.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | 4 | #ifndef STDLIB_NO_FIX_OF_RANDOM_DEVICE 5 | # ifdef __GNUC__ 6 | # undef _GLIBCXX_USE_RANDOM_TR1 7 | # define _GLIBCXX_USE_RANDOM_TR1 8 | # endif 9 | #endif 10 | #include 11 | -------------------------------------------------------------------------------- /source/list.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::list container. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/map.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::map container. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/set.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::set container. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/array.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::array container. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/chrono.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // C++ time utilites. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/complex.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::complex 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/deque.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::deque container. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /examples/basics/personalized_greeting/greeting.cpp: -------------------------------------------------------------------------------- 1 | // Source encoding: utf-8 with BOM ∩ 2 | #include 3 | using namespace std; 4 | 5 | auto main() 6 | -> int 7 | { 8 | cout << "Hi, what’s your name? "; 9 | string name; 10 | getline( cin, name ); 11 | cout << "Pleased to meet you, " << name << "!" << endl; 12 | } 13 | -------------------------------------------------------------------------------- /source/locale.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Localization utilities. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/streambuf.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // basic_streambuf 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/tuple.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::tuple class template . 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/vector.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::vector container. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/atomic.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Atomic operations library. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/bitset.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::bitset class template . 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/forward_declarations/fwd_iostreams.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Forward declarations of all classes in the input/output part of the library. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | -------------------------------------------------------------------------------- /source/iterator.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Container iterators. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/mutex.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // mutual exclusion primitives. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/stack.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::stack container adaptor. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/typeindex.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::type_index. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/codecvt.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Unicode conversion facilities. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/all/text/c_localization.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | // The C localization headers listed by (http://en.cppreference.com/w/cpp/header): 6 | #include // C localization utilities. 7 | -------------------------------------------------------------------------------- /source/exception.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Exception handling utilities. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/ratio.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Compile-time rational arithmetic. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/future.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Primitives for asynchronous computations. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/new.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Placement new, low-level memory management utilities. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/thread.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::thread class and supporting functions. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/typeinfo.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Runtime type information utilities. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /examples/basics/personalized_greeting/greeting.wide_text_version.cpp: -------------------------------------------------------------------------------- 1 | // Source encoding: utf-8 with BOM ∩ 2 | #include 3 | using namespace std; 4 | 5 | auto main() 6 | -> int 7 | { 8 | wcout << L"Hi, what’s your name? "; 9 | wstring name; 10 | getline( wcin, name ); 11 | wcout << L"Pleased to meet you, " << name << L"!" << endl; 12 | } 13 | -------------------------------------------------------------------------------- /examples/basics/ungood_encoding/ungood_encoding.utf-8_sans_bom.cpp: -------------------------------------------------------------------------------- 1 | // Source encoding: utf-8 sans BOM 2 | // Works by default with g++, gibberish with MSVC. 3 | #include // Used here: and 4 | using namespace std; 5 | 6 | auto main() 7 | -> int 8 | { 9 | cout << "Everybody likes Norwegian blåbærsyltetøy!" << endl; 10 | } 11 | -------------------------------------------------------------------------------- /source/algorithm.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Algorithms that operate on containers. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/c/time.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // C-style time/date utilites. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/forward_list.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::forward_list container. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/type_traits.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Compile-time type information. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/istream.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::basic_istream class template and several typedefs 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/queue.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::queue and std::priority_queue container adaptors. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/scoped_allocator.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Nested allocator class . 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/shared_mutex.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Shared mutual exclusion primitives. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/stdexcept.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Standard exception classes and some support. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/unordered_map.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::unordered_map container. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/unordered_set.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::unordered_set container. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/c/float.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Limits of floating point types. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/c/limits.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Limits of integral types. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/c/locale.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // C localization utilities. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/c/stdio.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // C's i/o functions, e.g. printf. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/utility.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Various utility components (e.g. std::pair, std::move). 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/condition_variable.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Thread waiting conditions. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/iomanip.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Helper functions to control the format or input and output. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/memory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Higher level memory management utilities, e.g. std::shared_ptr. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/valarray.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Class for representing and manipulating arrays of values. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/c/errno.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Macro containing the last error number. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/c/fenv.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Floating-point environment access functions. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/initializer_list.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::initializer_list class template . 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/numeric.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Numeric operations on values in containers, e.g. iota, accumulate. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/c/stdarg.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Handling of variable length argument lists. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/c/stdint.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Fixed-size types and limits of other types. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/c/uchar.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // C-style Unicode character conversion functions. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/iostream.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Standard stream objects: cin, cout, cerr, clog, wcin, wcout, wcerr, wclog 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/regex.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Classes, algorithms and iterators to support regular expression processing. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/all/text.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | // The text headers listed by (http://en.cppreference.com/w/cpp/header). 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/c/string.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Various narrow character string handling functions. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/c/wchar.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Various wide and multibyte string handling functions. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/fix/console_io.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 5 | 6 | #ifndef STDLIB_NO_FIX_OF_CONSOLE_IO 7 | # ifdef _WIN32 8 | # include 9 | # endif 10 | #endif 11 | 12 | #include 13 | -------------------------------------------------------------------------------- /source/functional.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Function objects, designed for use with the standard algorithms. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/ioswfd.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Forward declarations of all classes in the input/output part of the library. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/system_error.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Defines std::error_code, a platform-dependent error code. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/c/signal.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Functions and macro constants for signal management. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/c/iso646.h: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // As if each name from is placed in global namespace. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/c/stddef.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // typedefs for types such as size_t, ptrdiff_t, NULL and others. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/limits.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Standardized way to query properties of arithmetic types. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include // std::numeric_limits etc. 9 | #include 10 | -------------------------------------------------------------------------------- /source/random.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Random number generators and distributions. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/c/setjmp.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Macro (and function) that saves (and jumps) to an execution context. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/ios.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::ios_base class, std::basic_ios class template and several typedefs. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/c/assert.hpp: -------------------------------------------------------------------------------- 1 | // Intentionally no #pragma once // Source encoding: utf-8 with BOM ∩! 2 | // #include 3 | // 4 | // The `assert` macro. Note: can be reincluded with/without NDEBUG defined. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /source/c/complex.h: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // The effect is AS IF the C++ (not C) header `` were included. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/c/inttypes.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Formatting macros , intmax_t and uintmax_t math and conversions. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/c/stdbool.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Defines the __bool_true_false_are_defined compatibility macro constant. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/all/text/cpp_localization.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | // The localization headers listed by (http://en.cppreference.com/w/cpp/header): 6 | #include // Unicode conversion facilities. 7 | #include // Localization utilities. 8 | -------------------------------------------------------------------------------- /source/ostream.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::basic_ostream, std::basic_iostream class templates and several typedefs 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /source/all/numerics/number_range_limits.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include // Limits of integral types. 6 | #include // Limits of floating point types. 7 | #include // Standardized way to query properties of arithmetic types. 8 | -------------------------------------------------------------------------------- /examples/basics/command_line_arguments/command_line_arguments.textbook.cpp: -------------------------------------------------------------------------------- 1 | // Source encoding: utf-8 with BOM ∩ 2 | #include 3 | #include // std::setw 4 | using namespace std; 5 | 6 | auto main( int n_args, char* args[] ) 7 | -> int 8 | { 9 | cout << n_args << " command line arguments:\n"; 10 | for( int i = 0; i < n_args; ++i ) 11 | { 12 | cout << setw( 2 ) << i << ": “" << args[i] << "”.\n"; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /examples/basics/command_line_arguments/command_line_arguments.cpp: -------------------------------------------------------------------------------- 1 | // Source encoding: utf-8 with BOM ∩ 2 | #include 3 | using namespace std; 4 | 5 | auto main() 6 | -> int 7 | { 8 | const stdlib::process::Command_line_args args; 9 | 10 | cout << args.size() << " command line arguments:\n"; 11 | for( int i = 0; i < args.size(); ++i ) 12 | { 13 | cout << setw( 2 ) << i << ": “" << args[i] << "”.\n"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /source/fstream.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // basic_fstream, basic_ifstream, basic_ofstream, and several typedefs. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /source/c/ctype.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Functions to determine the type contained in character data. 5 | // Usally it's necessary to use `setlocale` first. 6 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | -------------------------------------------------------------------------------- /source/sstream.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // basic_stringstream, basic_istringstream, basic_ostringstream, several typedefs. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /examples/fixes/math_constants.cpp: -------------------------------------------------------------------------------- 1 | // Source encoding: utf-8 with BOM ∩ 2 | // 3 | // Define STDLIB_NO_MATH_CONSTANTS to turn off inclusion of the constants. 4 | 5 | #include 6 | using namespace std; 7 | namespace m = stdlib::math; 8 | 9 | auto main() -> int 10 | { 11 | cout << "Did you know, pi is roughly " << M_PI << " :-)" << endl; 12 | cout << setprecision( numeric_limits::digits10 ); 13 | cout << "Or more precisely, π ≈ " << m::pi << "." << endl; 14 | } 15 | -------------------------------------------------------------------------------- /source/c/wctype.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Functions for determining the type of wide character data. 5 | // In special cases (e.g. Turkey) it can be necessary to use `setlocale` first. 6 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | -------------------------------------------------------------------------------- /source/_impl/converter_buffer_size.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 5 | 6 | #include // stdlib::(Size, Index) 7 | 8 | namespace stdlib{ namespace impl{ 9 | using ext::Size; 10 | 11 | Size const converter_buffer_size = 2048; // Large enough for efficiency. 12 | 13 | }} // namespace stdlib::impl 14 | -------------------------------------------------------------------------------- /source/all/of_sublibrary/iterators.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // The C++ standard's section “Iterators library” (in C++14 that's §24). 5 | // The set of headers included here are those in C++14 §24.1/2 table 104. 6 | // 7 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 8 | 9 | 10 | // Iterator primitives 11 | // Predefined iterators 12 | // Stream iterators 13 | #include 14 | -------------------------------------------------------------------------------- /source/c/stdlib.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // E.g. `exit`. General purpose utilities: program control, dynamic memory allocation, 5 | // C++03 random numbers, C wide string functions, C sort and search. 6 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | -------------------------------------------------------------------------------- /source/all/numerics/integer_types.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Various useful aliases for integer types, plus support. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include // Formatting macros, intmax_t and uintmax_t math and conversions. 8 | #include // size_t, ptrdiff_t 9 | #include // Fixed-size types and limits of other types. 10 | -------------------------------------------------------------------------------- /source/string.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::basic_string class template, aliases std::string and std::wstring. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #ifndef NO_STDLIB_STRING_LITERALS 12 | using namespace std::string_literals; // E.g., `"Hi there!"s`. 13 | #endif 14 | -------------------------------------------------------------------------------- /source/all/text/cpp_strings.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // The C++ library's string handling headers, collected. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include // basic_string template, string and wstring. 8 | 9 | #include 10 | #if STDLIB_HAS_CPP17_FEATURES 11 | # include // basic_string_view template. 12 | #endif 13 | -------------------------------------------------------------------------------- /source/_impl/custom_process_command_line.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Copyright © 2017 Your Name, distributed under Boost license 1.0. 5 | 6 | #ifndef STDLIB_USE_CUSTOM_COMMAND_LINE_IMPL 7 | # error This file is only meaningful with STDLIB_USE_CUSTOM_COMMAND_LINE_IMPL. 8 | #endif 9 | 10 | #include 11 | 12 | // ... 13 | #error Not implemented (replace this file with your implementation) 14 | -------------------------------------------------------------------------------- /source/_impl/windows_console_io/constants.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 5 | 6 | #include 7 | #include // stdlib::ascii::* 8 | 9 | namespace stdlib{ namespace impl{ namespace windows_console_io{ 10 | 11 | const Size general_buffer_size = impl::converter_buffer_size; 12 | 13 | }}} // namespace stdlib::impl::windows_console_io 14 | -------------------------------------------------------------------------------- /examples/fixes/output_of_implicit_wide_cstring.cpp: -------------------------------------------------------------------------------- 1 | // Source encoding: utf-8 with BOM ∩ 2 | // 3 | // Define STDLIB_NO_OUTPUT_OF_IMPLICIT_WIDE_C_STRING_FIX to avoid the fix. 4 | // Without the fix the address of the string is presented, instead of text. 5 | 6 | #include 7 | using namespace std; 8 | using namespace stdlib::type_builders; // ptr_ 9 | 10 | struct Implicit_wide_string 11 | { 12 | operator ptr_() const { return L"Blåbærsyltetøy!"; } 13 | }; 14 | 15 | auto main() -> int 16 | { 17 | wcout << Implicit_wide_string{} << endl; 18 | } 19 | -------------------------------------------------------------------------------- /examples/fixes/randomly_random.cpp: -------------------------------------------------------------------------------- 1 | // Source encoding: utf-8 with BOM ∩ 2 | // 3 | // Run this program a number of times to see that the sequence is 4 | // different each time. 5 | // 6 | // Define STDLIB_NO_FIX_RANDOM_DEVICE to turn off the g++ fix. 7 | 8 | #include 9 | using namespace std; 10 | 11 | auto main() 12 | -> int 13 | { 14 | random_device entropy; 15 | uniform_int_distribution random_digit{ 0, 9 }; 16 | for( int i = 1; i <= 7; ++i ) 17 | { 18 | cout << random_digit( entropy ) << ' '; 19 | } 20 | cout << endl; 21 | } 22 | -------------------------------------------------------------------------------- /source/c/stdalign.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Functions and macro constants for signal management. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | 10 | // The isn't needed ( only defines 2 macros) and is not 11 | // provided by Visual C++ 2017, so here it's simply not included. 12 | // -- no -- #include 13 | 14 | #include 15 | -------------------------------------------------------------------------------- /source/all/non_io_fixes.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include // BEST IF FIRST. 6 | #include // For g++ needs to be before others. 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | -------------------------------------------------------------------------------- /source/all/of_sublibrary/atomic_operations.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // The C++ standard's section “Atomic operations library” (in C++14 that's §29). 5 | // The set of headers included here are those in C++14 §29.1/2 table 145. 6 | // 7 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 8 | 9 | 10 | // Order and Consistency 11 | // Lock-free Property 12 | // Atomic Types 13 | // Operations on Atomic Types 14 | // Flag Type and Operations 15 | // Fences 16 | #include 17 | -------------------------------------------------------------------------------- /source/extension/STDLIB_NORETURN.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 5 | 6 | #include 7 | 8 | #if !defined( STDLIB_NORETURN ) 9 | # if defined( _MSC_VER ) 10 | # define STDLIB_NORETURN __declspec( noreturn ) 11 | # elif defined( __GNUC__ ) 12 | # define STDLIB_NORETURN __attribute__(( noreturn )) 13 | # else 14 | # define STDLIB_NORETURN [[noreturn]] 15 | # endif 16 | #endif 17 | -------------------------------------------------------------------------------- /source/_impl/winapi_types.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include // ptr_ 6 | 7 | namespace stdlib{ namespace impl{ namespace winapi{ 8 | using namespace stdlib::ext; 9 | 10 | using Bool = int; 11 | using Handle = ptr_; 12 | using DWord = unsigned; static_assert( sizeof( DWord ) == 4, "!" ); 13 | using UInt = unsigned; 14 | 15 | }}} // namespace stdlib::impl::winapi 16 | -------------------------------------------------------------------------------- /source/all/of_sublibrary/algorithms.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // The C++ standard's section “Algorithms library” (in C++14 that's §25). 5 | // The set of headers included here are those in C++14 §25.1/2 table 112. 6 | // 7 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 8 | 9 | 10 | // Non-modifying sequence operations 11 | // Mutating sequence operations 12 | // Sorting and related operations 13 | #include 14 | 15 | // C library algorithms 16 | #include 17 | -------------------------------------------------------------------------------- /source/all/of_sublibrary/regular_expressions.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // The C++ standard's section “Regular expressions library” (in C++14 that's §28). 5 | // The set of headers included here are those in C++14 §28.1/2 table 136. 6 | // 7 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 8 | 9 | 10 | // Constants 11 | // Exception type 12 | // Traits 13 | // Regular expression template 14 | // Submatches 15 | // Match results 16 | // Algorithms 17 | // Iterators 18 | #include 19 | -------------------------------------------------------------------------------- /source/_impl/winapi_constants.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include // ptr_ 6 | 7 | namespace stdlib{ namespace impl{ namespace winapi{ 8 | 9 | int const max_path_length = 260; // MAX_PATH 10 | 11 | enum: UInt 12 | { 13 | cp_acp = 0, // ANSI codepage id 14 | cp_utf8 = 65001 // UTF-8 codepage id 15 | }; 16 | 17 | }}} // namespace stdlib::impl::winapi 18 | -------------------------------------------------------------------------------- /source/all/of_sublibrary/localization.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // The C++ standard's section “Localization library” (in C++14 that's §22). 5 | // The set of headers included here are those in C++14 §22.1/2 table 80. 6 | // 7 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 8 | 9 | 10 | // Locales 11 | // Standard locale Categories 12 | #include 13 | 14 | // Standard code conversion facets 15 | #include 16 | 17 | // C library locales 18 | #include 19 | 20 | -------------------------------------------------------------------------------- /source/fix/default_locale.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // The default locale needs to be set up 5 | // • to make wide streams work in Unix-land, and 6 | // • to make narrow character classification functions work in Windows. 7 | // 8 | // STDLIB_NO_FIX_OF_DEFAULT_C_LOCALE suppresses the C locale auto-config. 9 | // STDLIB_NO_FIX_OF_DEFAULT_CPP_LOCALE suppresses the C++ locale auto-config. 10 | // 11 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 12 | 13 | #include 14 | #include 15 | -------------------------------------------------------------------------------- /source/all/of_sublibrary/diagnostics.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // The C++ standard's section “Diagnostics library” (in C++14 that's §19). 5 | // The set of headers included here are those in C++14 §19/2 table 41. 6 | // 7 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 8 | 9 | 10 | // Exception classes: 11 | #include 12 | 13 | // Assertions: 14 | #include 15 | 16 | // Error numbers: 17 | #include 18 | 19 | // System error support: 20 | #include 21 | -------------------------------------------------------------------------------- /source/fix/msvc_named_boolean_operators.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Standard C++ provides “and”, “or” and “not”. Visual C++ doesn't, by default. See the 5 | // article on “iso646” at . 6 | // 7 | // STDLIB_NO_FIX_OF_NAMED_BOOLEAN_OPERATORS suppresses this conformance measure. 8 | // 9 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 10 | 11 | #ifndef STDLIB_NO_FIX_OF_NAMED_BOOLEAN_OPERATORS 12 | # if defined( _MSC_VER ) 13 | # include 14 | # endif 15 | #endif 16 | -------------------------------------------------------------------------------- /examples/fixes/console_io.cpp: -------------------------------------------------------------------------------- 1 | // Source encoding: utf-8 with BOM ∩ 2 | // 3 | // Define STDLIB_NO_CONSOLE_IO_FIX to turn off the console i/o fix. 4 | // Define STDLIB_NO_MSVC_UTF8_LITERALS_FIX to turn off forced UTF-8 literals. 5 | 6 | #include 7 | using namespace std; 8 | 9 | auto main() -> int 10 | { 11 | cout << u8"Every 日本国 кошка likes Norwegian blåbærsyltetøy." << endl; 12 | cout << "I said, every 日本国 кошка likes Norwegian blåbærsyltetøy." << endl; 13 | cout << endl; 14 | cout << "By the way, what’s your name? "; 15 | string name; 16 | getline( cin, name ); 17 | cout << "Pleased to meet you, " << name << "!" << endl; 18 | } 19 | -------------------------------------------------------------------------------- /examples/fixes/s_literal_operator.cpp: -------------------------------------------------------------------------------- 1 | // Source encoding: utf-8 with BOM ∩ 2 | // 3 | // Define NO_STDLIB_STRING_LITERALS to not add `s` literal operator to the 4 | // global namespace (i.e., not do `using namespace std::string_literals;`). 5 | 6 | #include 7 | using std::cout; 8 | using std::endl; 9 | using std::setw; 10 | 11 | auto main( int n_args, char* args[] ) 12 | -> int 13 | { 14 | cout << "Arguments:" << endl; 15 | for( int i = 0; i < n_args; ++i ) 16 | { 17 | // The concatenation here works because "“"s is a std::string. 18 | cout << setw( 2 ) << i << ": " << setw( 40 ) << "“"s + args[i] + "”" << endl; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/fixes/alternative_keywords.cpp: -------------------------------------------------------------------------------- 1 | // Source encoding: utf-8 with BOM ∩ 2 | // 3 | // Define STDLIB_NO_NAMED_BOOLEAN_OPERATORS_FIX to turn off inclusion. 4 | 5 | #include 6 | using namespace std; 7 | 8 | auto main( int n_args, char* args[] ) 9 | -> int 10 | { 11 | if( n_args == 2 and args[1] == "secret_password"s ) 12 | { 13 | cout << "You guessed the secret password! Fantastic!" << endl; 14 | return EXIT_SUCCESS; 15 | } 16 | else if( n_args != 2 or args[1] == "/?"s or args[1] == "--help"s ) 17 | { 18 | cerr << "Usage: " << args[0] << " YOUR-PASSWORD-GUESS" << endl; 19 | } 20 | return EXIT_FAILURE; 21 | } 22 | -------------------------------------------------------------------------------- /source/all/of_sublibrary/thread_support.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // The C++ standard's section “Thread support library” (in C++14 that's §30). 5 | // The set of headers included here are those in C++14 §30.1/1 table 149. 6 | // 7 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 8 | 9 | 10 | // Threads 11 | #include 12 | 13 | // Mutual exclusion 14 | #include 15 | #include 16 | 17 | // Condition variables 18 | #include 19 | 20 | // Futures 21 | #include 22 | -------------------------------------------------------------------------------- /source/fix/msvc_utf8_literals.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // See e.g. the MSDN article on "pragma execution_character_set" 5 | // at . 6 | // 7 | // STDLIB_NO_MSVC_UTF8_LITERALS_FIX suppresses forced UTF-8 literals. 8 | // 9 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 10 | 11 | #ifndef STDLIB_NO_FIX_OF_MSVC_UTF8_LITERALS 12 | # if defined( _MSC_VER ) 13 | # if _MSC_VER >= 1700 // Visual C++ 2015 or later 14 | # pragma execution_character_set( "utf-8" ) // UTF-8 narrow literals. 15 | # endif 16 | # endif 17 | #endif 18 | -------------------------------------------------------------------------------- /source/all/of_sublibrary/strings.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // The C++ standard's section “Strings library” (in C++14 that's §21). 5 | // The set of headers included here are those in C++14 §21.1/2 table 61. 6 | // 7 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 8 | 9 | 10 | // Character traits 11 | // String classes 12 | #include 13 | 14 | // Null-terminated sequence utilities 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | -------------------------------------------------------------------------------- /examples/c++17/filesystem.cpp: -------------------------------------------------------------------------------- 1 | // Source encoding: utf-8 with BOM ∩ 2 | // 3 | // For Visual C++ 2017 and earlier compile with option “/std::c++latest”. 4 | // For g++, “g++ filesystem.cpp -D STDLIB_USE_EXPERIMENTAL_CPP17 -lstdc++fs”. 5 | 6 | #include 7 | #include 8 | using namespace std; 9 | namespace fs = std::filesystem; 10 | 11 | auto main( int, char* args[] ) -> int 12 | { 13 | const auto program_path = fs::absolute( args[0] ); 14 | const auto program_folder_path = program_path.parent_path(); 15 | 16 | cout 17 | << "This program resides in “" 18 | << program_folder_path.u8string() //! Always use u8string(). 19 | << "”." << endl; 20 | } 21 | -------------------------------------------------------------------------------- /examples/fixes/native_locale_as_default.cpp: -------------------------------------------------------------------------------- 1 | // Source encoding: utf-8 with BOM ∩ 2 | // 3 | // Define STDLIB_NO_DEFAULT_C_LOCALE_FIX to suppress the C locale config. 4 | // Define STDLIB_NO_DEFAULT_CPP_LOCALE_FIX to suppress the C++ locale config. 5 | // 6 | // Note: for wide stream console output this is mostly about *nix-land. In 7 | // Windows the console i/o fix takes care of wide stream console output. 8 | 9 | #include 10 | using namespace std; 11 | 12 | auto main() -> int 13 | { 14 | // The locale can affect numerical output, e.g. European decimal comma. 15 | wcout << L"Did you know, pi is roughly " << M_PI << L" :-)" << endl; 16 | wcout << L"Norwegian blåbærsyltetøy is a fav of 日本国 кошкаs." << endl; 17 | } 18 | -------------------------------------------------------------------------------- /source/all/ppp_facilities.unqualified.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Corresponds to the `"std_lib_facilities.h"` header for Bjarne Stroustrup's book 5 | // “Programming: Principles and Practice Using C++”, plus `hopefully` and `fail`. 6 | // 7 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 8 | #pragma once 9 | 10 | #include 11 | using namespace std; // This directive is in Stroustrup's original header. 12 | using namespace ppp; // `error` in global namespace is also in original. 13 | using namespace ppp_ex; // Same convention for our `hopefully` and `fail`. 14 | -------------------------------------------------------------------------------- /source/all/text/c_strings.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // The C library's string handling headers, collected. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include // Functions to determine the type contained in character data. 8 | #include // Functions for determining the type of wide character data. 9 | #include // Various narrow character string handling functions. 10 | #include // Various wide and multibyte string handling functions. 11 | #include // C-style Unicode character conversion functions. 12 | -------------------------------------------------------------------------------- /source/extension/size_types.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include 6 | 7 | #include // ptrdiff_t, size_t 8 | #include 9 | 10 | namespace stdlib{ namespace ext{ 11 | 12 | using Size = ptrdiff_t; 13 | using Index = Size; 14 | 15 | using U_size = size_t; 16 | using U_index = U_size; 17 | 18 | namespace basic_types 19 | { 20 | using ext::Size, ext::Index, ext::U_size, ext::U_index; 21 | } // namespace basic_types 22 | 23 | }} // namespace stdlib::ext 24 | -------------------------------------------------------------------------------- /source/c/tgmath.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // In C11 `tgmath.h` defines type-generic macros so that e.g. `fabs(x)` can be 5 | // invoked with either floating point or complex argument. In C++ this is 6 | // achieved via ordinary function overloading. I.e. is not meaningful 7 | // in C++, but the C++ standard library provides it for compatibility. 8 | // 9 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 10 | 11 | #include 12 | #include // Non-C++-compatible macro definitions, + includes. 13 | // #include // Not available with Visual C++ 2017. 14 | #include 15 | -------------------------------------------------------------------------------- /source/extension/Byte_order.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include 6 | 7 | namespace stdlib{ namespace ext{ 8 | struct Byte_order 9 | { 10 | enum Enum 11 | { 12 | little_endian = STDLIB_LITTLE_ENDIAN, 13 | big_endian = STDLIB_BIG_ENDIAN, 14 | mixed_endian = STDLIB_MIXED_ENDIAN 15 | }; 16 | }; 17 | 18 | constexpr 19 | inline auto system_byte_order() 20 | -> Byte_order::Enum 21 | { return static_cast( STDLIB_SYSTEM_BYTE_ORDER ); } 22 | 23 | }} // namespace stdlib::ext 24 | -------------------------------------------------------------------------------- /examples/basics/command_line_arguments/command_line_arguments.most_portable.cpp: -------------------------------------------------------------------------------- 1 | // Source encoding: utf-8 with BOM ∩ 2 | #include 3 | using namespace stdlib::type_builders; // ptr_, ref_ 4 | using stdlib::process::Command_line_args; // Command_line_args 5 | 6 | namespace my{ 7 | void cppmain( ref_ args ) 8 | { 9 | using namespace std; 10 | cout << args.size() << " command line arguments:\n"; 11 | for( int i = 0; i < args.size(); ++i ) 12 | { 13 | cout << setw( 2 ) << i << ": “" << args[i] << "”.\n"; 14 | } 15 | } 16 | } // namespace my 17 | 18 | auto main( const int n, const ptr_> arg_pointers ) 19 | -> int 20 | { my::cppmain( Command_line_args::from_os_or_else_from( n, arg_pointers ) ); } 21 | -------------------------------------------------------------------------------- /source/all/of_sublibrary/numerics.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // The C++ standard's section “Numerics library” (in C++14 that's §26). 5 | // The set of headers included here are those in C++14 §26.1/2 table 114. 6 | // 7 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 8 | 9 | 10 | // Floating-Point Environment 11 | #include 12 | 13 | // Complex Numbers 14 | #include 15 | 16 | // Random number generation 17 | #include 18 | 19 | // Numeric arrays 20 | #include 21 | 22 | // Generalized numeric operations 23 | #include 24 | 25 | // C library 26 | #include 27 | #include 28 | #include // E.g. abs(int) 29 | -------------------------------------------------------------------------------- /source/all/of_sublibrary/containers.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // The C++ standard's section “Containers library” (in C++14 that's §23). 5 | // The set of headers included here are those in C++14 §23.1/2 table 95. 6 | // 7 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 8 | 9 | 10 | // Sequence containers 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | // Associative containers 18 | #include 19 | #include 20 | 21 | // Unordered associative containers 22 | #include 23 | #include 24 | 25 | // Container adaptors 26 | #include 27 | #include 28 | -------------------------------------------------------------------------------- /examples/basics/ungood_encoding/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | 5 | { 6 | "name": "(gdb) Launch", 7 | "type": "cppdbg", 8 | "request": "launch", 9 | "program": "${workspaceRoot}/a.exe", 10 | "args": [], 11 | "stopAtEntry": false, 12 | "cwd": "${workspaceRoot}", 13 | "environment": [], 14 | "externalConsole": true, 15 | "MIMode": "gdb", 16 | "miDebuggerPath": "C:/Program Files (x86)/mingw-w64/i686-6.3.0-posix-dwarf-rt_v5-rev1/mingw32/bin/gdb.exe", 17 | "setupCommands": [ 18 | { 19 | "description": "Enable pretty-printing for gdb", 20 | "text": "-enable-pretty-printing", 21 | "ignoreFailures": true 22 | } 23 | ] 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /source/extension/char_path.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Best effort compatible-with-runtime-library path. 5 | // In Windows some result path items can be alternate short names, if that’s 6 | // available for the file system, unless the long path is all ASCII, in which 7 | // case it’s just returned as-is. 8 | // 9 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 10 | 11 | #include 12 | 13 | #include // stdlib::(ref_) 14 | #include 15 | 16 | // For exposition only (each included header below includes this itself): 17 | #include 18 | 19 | #ifdef _WIN32 20 | # include 21 | #else 22 | # include 23 | #endif 24 | -------------------------------------------------------------------------------- /source/all/basics.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include 6 | 7 | #include // E.g. & 8 | #include // E.g. , & 9 | #include // std::vector 10 | #include // std::(function, invoke) 11 | 12 | #include // stdlib::ext::(hopefully, fail) 13 | #include // stdlib::ext::(Index, Size) 14 | #include // stdlib::ext::(ref_, ptr_, ...) 15 | #include // stdlib::ext::(Command_line_args, Command_argv_array) 16 | -------------------------------------------------------------------------------- /source/_impl/windows_process_command_line/api.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include // ptr_ 6 | 7 | #include // winapi::(DWord, ...) 8 | 9 | #ifdef _MSC_VER 10 | # pragma comment( lib, "shell32.lib" ) // For CommandLineToArgvW 11 | #endif 12 | 13 | namespace stdlib{ namespace impl{ namespace winapi{ 14 | 15 | extern "C" 16 | auto __stdcall GetCommandLineW() 17 | -> ptr_; 18 | 19 | extern "C" 20 | auto __stdcall CommandLineToArgvW( 21 | ptr_ lpCmdLine, 22 | ptr_ pNumArgs 23 | ) -> ptr_>; 24 | 25 | extern "C" 26 | auto __stdcall LocalFree( Handle hMem ) 27 | -> Handle; 28 | 29 | }}} // stdlib::impl::winapi 30 | -------------------------------------------------------------------------------- /source/all/of_sublibrary/input_output.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // The C++ standard's section “Input/output library” (in C++14 that's §27). 5 | // The set of headers included here are those in C++14 §27.1/2 table 121. 6 | // 7 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 8 | 9 | 10 | // Forward declarations 11 | #include 12 | 13 | // Standard iostream objects 14 | #include 15 | 16 | // Iostreams base classes 17 | #include 18 | 19 | // Stream buffers 20 | #include 21 | 22 | // Formatting and manipulators 23 | #include 24 | #include 25 | #include 26 | 27 | // String streams 28 | #include 29 | 30 | // File streams 31 | #include 32 | #include 33 | #include 34 | -------------------------------------------------------------------------------- /source/fix/msvc_wolfcalls_about_std_functions.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // See e.g. Visual C++ (MSVC) warning C4996, or the article about _SCL_SECURE_NO_WARNINGS 5 | // at . 6 | // 7 | // NOTE: THIS WARNING SUPPRESSION IS NOT GUARANTEED TO WORK UNLESS IT'S DONE BEFORE ANY 8 | // STANDARD LIBRARY HEADERS ARE INCLUDED. TO BE SURE (WRT. DIRECTLY INCLUDED HEADERS) USE 9 | // A FORCED INCLUDE OF THIS HEADER, OR A FORCED INCLUDE OF . 10 | // 11 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 12 | 13 | #if defined( _MSC_VER ) && !defined( STDLIB_NO_FIX_OF_MSVC_WOLFCALLS_ABOUT_STD_FUNCTIONS ) 14 | # undef _SCL_SECURE_NO_WARNINGS // Avoid extra sillywarning on the #define. 15 | # define _SCL_SECURE_NO_WARNINGS 16 | # undef _CRT_SECURE_NO_WARNINGS 17 | # define _CRT_SECURE_NO_WARNINGS 18 | #endif 19 | -------------------------------------------------------------------------------- /source/optional.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // A boxed value, where the box can be empty. Conceptual view: pointer. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include // STDLIB_COMPILER_SUPPORTS_CPP17 8 | #include 9 | 10 | #if STDLIB_USE_EXPERIMENTAL_CPP17 11 | # include 12 | #elif STDLIB_COMPILER_SUPPORTS_CPP17 13 | # include 14 | #else 15 | # ifdef _MSC_VER 16 | # error " is apparently not available (use option `/std:c++latest`?)." 17 | # else 18 | # error " appears not available (try define STDLIB_USE_EXPERIMENTAL_CPP17?)." 19 | # endif 20 | #endif 21 | 22 | #ifdef STDLIB_HOIST_UP_OPTIONAL_TEMPLATE 23 | namespace std { 24 | using experimental::optional; 25 | } // namespace std; 26 | #endif 27 | 28 | #include 29 | -------------------------------------------------------------------------------- /source/variant.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // A discriminated union, essentially a boxed value of one of N specified types. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include // STDLIB_COMPILER_SUPPORTS_CPP17 8 | #include 9 | 10 | #if STDLIB_USE_EXPERIMENTAL_CPP17 11 | # include 12 | #elif STDLIB_COMPILER_SUPPORTS_CPP17 13 | # include 14 | #else 15 | # ifdef _MSC_VER 16 | # error " is apparently not available (use option `/std:c++latest`?)." 17 | # else 18 | # error " appears not available (try define STDLIB_USE_EXPERIMENTAL_CPP17?)." 19 | # endif 20 | #endif 21 | 22 | #ifdef STDLIB_HOIST_UP_VARIANT_TEMPLATE 23 | namespace std { 24 | using experimental::variant; 25 | } // namespace std; 26 | #endif 27 | 28 | #include 29 | -------------------------------------------------------------------------------- /examples/fixes/ansi_escape_sequences.cpp: -------------------------------------------------------------------------------- 1 | // Source encoding: utf-8 with BOM ∩ 2 | // 3 | // Define STDLIB_NO_ANSI_ESCAPES_FIX to not enable interpretation of escape codes. 4 | // (Depending on the system they might still be interpreted, but in Windows stdlib 5 | // won't then call SetConsoleMode to tell the console window to interpret them.) 6 | // 7 | // For documentation of the sequences supported by Windows 10 console windows, see 8 | // the article titled “Console Virtual Terminal Sequences” in MSDN Library 9 | // (Microsoft Developer Network Library), which was available at 10 | // 11 | // at the time when I wrote this example program, medio June 2017. 12 | 13 | #include 14 | using namespace std; 15 | 16 | auto main() -> int 17 | { 18 | const auto s = 19 | "\x1B[37mColored text is fun.\n" 20 | "Look, here’s some \x1B[91mred text\x1B[37m!\n" 21 | "And here’s some \x1B[92mgreen text\x1B[37m, amazing!"; 22 | cout << s << endl; 23 | } 24 | -------------------------------------------------------------------------------- /source/string_view.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // basic_string_view template, specializations string_view and wstring_view. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include // STDLIB_COMPILER_SUPPORTS_CPP17 8 | #include 9 | 10 | #if STDLIB_USE_EXPERIMENTAL_CPP17 11 | # include 12 | #elif STDLIB_COMPILER_SUPPORTS_CPP17 13 | # include 14 | #else 15 | # ifdef _MSC_VER 16 | # error " is apparently not available (use option `/std:c++latest`?)." 17 | # else 18 | # error " appears not available (try define STDLIB_USE_EXPERIMENTAL_CPP17?)." 19 | # endif 20 | #endif 21 | 22 | #ifdef STDLIB_HOIST_UP_STRINGVIEW_TEMPLATE 23 | namespace std { 24 | using experimental::string_view; 25 | } // namespace std; 26 | #endif 27 | 28 | #include 29 | -------------------------------------------------------------------------------- /source/_impl/windows_char_path/apiwrap.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include // stdlib::(Size, array_size) 6 | #include // ...winapi::(DWord, max_path_length, ...) 7 | 8 | #include // std::wstring 9 | 10 | namespace stdlib{ namespace impl{ namespace apiwrap{ 11 | using std::wstring; 12 | 13 | // This function isn't used because it doesn't convert certain short non-ASCII items. 14 | inline auto get_short_path( wstring const& long_path ) 15 | -> wstring 16 | { 17 | Size const n = long_path.length(); 18 | if( n == 0 ) { return L""; } 19 | 20 | wchar_t buffer[winapi::max_path_length]; 21 | Size const short_length = winapi::GetShortPathNameW( 22 | long_path.c_str(), buffer, array_size( buffer ) 23 | ); 24 | return wstring{ buffer, buffer + short_length }; // L"" if fail. 25 | } 26 | 27 | }}} // namespace stdlib::impl::apiwrap 28 | -------------------------------------------------------------------------------- /source/_impl/general_char_path.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Best effort compatible-with-runtime-library path. 5 | // In Windows some result path items can be alternate short names, if that’s 6 | // available for the file system, unless the long path is all ASCII, in which 7 | // case it’s just returned as-is. 8 | // 9 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | namespace stdlib{ 19 | using std::string; 20 | using std::wstring; 21 | 22 | inline auto char_path_with_substitution( const bool substitution_allowed, wstring long_path ) 23 | -> string 24 | { (void) substitution_allowed; return utf8_from( long_path ); } 25 | 26 | inline auto char_path_with_substitution( const bool substitution_allowed, string long_utf8_path ) 27 | -> string 28 | { (void) substitution_allowed; return long_utf8_path; } 29 | 30 | } // namespace stdlib 31 | -------------------------------------------------------------------------------- /source/_impl/windows_process_command_line.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #ifndef _WIN32 6 | # error This file is only meaningful in Windows. 7 | #endif 8 | 9 | #include // 10 | #include // stdlib::utf8_from 11 | #include // impl::apiwrap::* 12 | 13 | namespace stdlib{ namespace ext{ 14 | constexpr 15 | inline auto has_original_command_line() 16 | -> bool 17 | { return true; } 18 | 19 | inline auto process::command_line() 20 | -> string 21 | { return utf8_from( stdlib::impl::apiwrap::command_line_ptr() ); }; 22 | 23 | inline process::Command_line_args::Command_line_args() 24 | { 25 | const stdlib::impl::apiwrap::Command_line_args wide_items; 26 | for( int i = 0; i < wide_items.count; ++i ) 27 | { 28 | items_.push_back( utf8_from( wide_items.items[i] ) ); 29 | } 30 | } 31 | }} // namespace stdlib::ext 32 | 33 | -------------------------------------------------------------------------------- /source/all/of_sublibrary/general_utilities.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // The C++ standard's section “General utilities library” (in C++14 that's §20). 5 | // The set of headers included here are those in C++14 §20.1/1 table 44. 6 | // 7 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 8 | 9 | 10 | // Utility components 11 | // Pairs 12 | // Compile time integer sequences 13 | #include 14 | 15 | // Tuples 16 | #include 17 | 18 | // Fixed-size sequences of bits 19 | #include 20 | 21 | // Memory 22 | // Smart pointers 23 | #include 24 | #include 25 | #include 26 | 27 | // Function objects 28 | #include 29 | 30 | // Type traits 31 | #include 32 | 33 | // Compile-time rational arithmetic 34 | #include 35 | 36 | // Time utilities 37 | #include 38 | #include 39 | 40 | // Scoped allocators 41 | #include 42 | 43 | // Type indexes 44 | #include 45 | -------------------------------------------------------------------------------- /source/extension/Codecvt.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include 6 | 7 | #ifdef _MSC_VER 8 | # undef _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING 9 | # define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING 1 10 | #endif 11 | 12 | #include // std::codecvt_utf8 13 | #include // stdlib::system_byte_order() 14 | 15 | namespace stdlib{ namespace ext{ 16 | using std::codecvt_mode; 17 | using std::codecvt_utf8_utf16; 18 | using std::little_endian; // A value of bits enumeration std::codecvt_enum. 19 | 20 | using Codecvt = codecvt_utf8_utf16< 21 | wchar_t, 22 | 0x10ffff, // Max value of UTF-16 encoding, i.e. highest code point. 23 | (system_byte_order() == Byte_order::little_endian? little_endian : codecvt_mode{}) 24 | >; 25 | using Codecvt_result = decltype( Codecvt::ok ); // enum 26 | using Codecvt_state = Codecvt::state_type; // enum 27 | 28 | }} // namespace stdlib::ext 29 | -------------------------------------------------------------------------------- /source/all/of_sublibrary/language_support.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // The C++ standard's section “Language support library” (in C++14 that's §18). 5 | // The set of headers included here are those in C++14 §18/2 table 29. 6 | // 7 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 8 | 9 | 10 | // Types: 11 | #include 12 | 13 | // Implementation properties: 14 | #include 15 | #include 16 | #include 17 | 18 | // Integer types: 19 | #include 20 | 21 | // Start and termination: 22 | #include 23 | 24 | // Dynamic memory management: 25 | #include 26 | 27 | // Type identification: 28 | #include 29 | 30 | // Exception handling: 31 | #include 32 | 33 | // Initializer lists: 34 | #include 35 | 36 | // Other runtime support: 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | -------------------------------------------------------------------------------- /source/all/numerics.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | // The numerics headers listed by (http://en.cppreference.com/w/cpp/header), 6 | #include // Floating-point environment access functions. 7 | #include // Common mathematics functions, floating point overloads of `abs`. 8 | #include // std::complex 9 | #include // Numeric operations on values in containers, e.g. iota. 10 | #include // Random number generators and distributions 11 | #include // Compile-time rational arithmetic. 12 | #include // Class for representing and manipulating arrays of values. 13 | 14 | // Not listed in this category by cppreference, but useful/necessary: 15 | #include // std::(min, max, accumulate, etc.) 16 | #include // Various useful aliases for integer types, plus support. 17 | #include // E.g. INT_MAX, std::numeric_limits::max(). 18 | #include // E.g. integer overloads of `abs`. 19 | -------------------------------------------------------------------------------- /source/all/io.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | // The i/o headers listed by (http://en.cppreference.com/w/cpp/header), 6 | // except the deprecated header; use instead. 7 | #include // C's i/o functions, e.g. printf. 8 | #include // basic_fstream, basic_ifstream, basic_ofstream, and several typedefs. 9 | #include // Helper functions to control the format or input and output. 10 | #include // Forward declarations of all classes in the input/output part of the library. 11 | #include // Standard stream objects: cin, cout, cerr, clog, wcin, wcout, wcerr, wclog 12 | #include // std::basic_istream class template and several typedefs. 13 | #include // std::basic_ostream, std::basic_iostream class templates and several typedefs 14 | #include // basic_stringstream, basic_istringstream, basic_ostringstream, several typedefs. 15 | #include // basic_streambuf 16 | 17 | // Not listed in this category by cppreference, but useful/necessary: 18 | #include 19 | #include 20 | -------------------------------------------------------------------------------- /source/extension/STDLIB_SYSTEM_BYTE_ORDER.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 5 | 6 | #include 7 | 8 | #ifdef __BYTE_ORDER__ 9 | # if !( defined( __ORDER_LITTLE_ENDIAN__ ) && \ 10 | defined( __ORDER_BIG_ENDIAN__) && \ 11 | defined( __ORDER_PDP_ENDIAN__ ) ) 12 | # error __BYTE_ORDER__ is defined but one or more value macros are missing. 13 | # endif 14 | # 15 | # define STDLIB_SYSTEM_BYTE_ORDER __BYTE_ORDER__ 16 | # 17 | # define STDLIB_LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ // 1234 18 | # define STDLIB_BIG_ENDIAN __ORDER_BIG_ENDIAN__ // 4321 19 | # define STDLIB_MIXED_ENDIAN __ORDER_PDP_ENDIAN__ // 3412 20 | #else 21 | # if defined( _WIN32 ) 22 | # define STDLIB_SYSTEM_BYTE_ORDER STDLIB_LITTLE_ENDIAN 23 | # elif defined( __BIG_ENDIAN__ ) || defined( __BIG_ENDIAN ) || defined( _BIG_ENDIAN ) 24 | # define STDLIB_SYSTEM_BYTE_ORDER STDLIB_BIG_ENDIAN 25 | # else 26 | # error Please define STDLIB_SYSTEM_BYTE_ORDER, e.g. as STDLIB_LITTLE_ENDIAN. 27 | # endif 28 | # 29 | # // The values used by the g++ compiler: 30 | # define STDLIB_LITTLE_ENDIAN 1234 31 | # define STDLIB_BIG_ENDIAN 4321 32 | # define STDLIB_MIXED_ENDIAN 3412 33 | #endif 34 | -------------------------------------------------------------------------------- /source/fix/default_c_locale.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // The default locale needs to be set up 5 | // • to make wide streams work in Unix-land, and 6 | // • to make narrow character classification functions work in Windows. 7 | // 8 | // STDLIB_NO_FIX_OF_DEFAULT_C_LOCALE suppresses the locale auto-config. 9 | // 10 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #ifdef STDLIB_DEBUG_C_LOCALE 17 | # include 18 | # include 19 | #endif 20 | 21 | namespace stdlib{ namespace impl{ namespace default_c_locale{ 22 | 23 | class Envelope 24 | { 25 | private: 26 | 27 | ~Envelope() { setlocale( LC_ALL, "C" ); } 28 | 29 | Envelope() 30 | noexcept 31 | { 32 | char const* const s = setlocale( LC_ALL, "" ); assert( s != nullptr ); 33 | setlocale( LC_NUMERIC, "C" ); 34 | (void) s; 35 | #ifdef STDLIB_DEBUG_C_LOCALE 36 | fprintf( stderr, "!C locale set to \"%s\".\n", s ); fflush( stderr ); 37 | #endif 38 | } 39 | 40 | public: 41 | static auto make_singleton() 42 | -> bool 43 | { 44 | static Envelope the_envelope; 45 | return true; 46 | } 47 | }; 48 | 49 | # ifndef STDLIB_NO_FIX_OF_DEFAULT_C_LOCALE 50 | const bool dummy = Envelope::make_singleton(); 51 | # endif 52 | 53 | }}} // namespace stdlib::impl::default_c_locale 54 | -------------------------------------------------------------------------------- /source/extension/hopefully_and_fail.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include 6 | 7 | #include 8 | #include // stdlib::(ref_) 9 | 10 | #include 11 | #include 12 | 13 | // Silly-warning suppression: 14 | #if defined( _MSC_VER ) 15 | # pragma warning( disable: 4646 ) // 'noreturn' function has non-void return type. 16 | #endif 17 | 18 | namespace stdlib{ namespace ext{ 19 | namespace impl { 20 | using std::string; 21 | using std::runtime_error; 22 | 23 | struct Success{}; 24 | struct Failure{}; 25 | 26 | template< class Value > 27 | auto operator>>( Value const& v, Failure ) 28 | -> bool 29 | { return not (v >> Success{}); } 30 | 31 | inline auto hopefully( const bool condition ) 32 | -> bool 33 | { return condition; } 34 | 35 | inline STDLIB_NORETURN auto fail( ref_ message ) 36 | -> bool 37 | { throw runtime_error( message ); } 38 | } // namespace impl 39 | 40 | inline namespace hopefully_and_fail { 41 | using impl::Success; 42 | using impl::Failure; 43 | using impl::operator>>; 44 | using impl::hopefully; 45 | using impl::fail; 46 | } // inline namespace hopefully_and_fail 47 | 48 | }} // namespace stdlib::ext 49 | -------------------------------------------------------------------------------- /source/all/ppp_facilities.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Corresponds to the `"std_lib_facilities.h"` header for Bjarne Stroustrup's book 5 | // “Programming: Principles and Practice Using C++”, plus `hopefully` and `fail`, 6 | // except that here there's no evil `using namespace std;`. 7 | // 8 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 9 | 10 | 11 | // Silly-warning suppression: 12 | #if defined( _MSC_VER ) 13 | # define _SCL_SECURE_NO_WARNINGS // Call to 'std::copy' (etc.) may be unsafe. 14 | #endif 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | //using namespace std; No, Bjarne. No! 28 | 29 | namespace ppp { 30 | using std::string; 31 | using std::runtime_error; 32 | using stdlib::ref_; 33 | 34 | // Bjarne's functions: 35 | 36 | inline STDLIB_NORETURN void error( ref_ message ) 37 | { throw runtime_error( message ); } 38 | 39 | inline STDLIB_NORETURN void error( ref_ s1, ref_ s2 ) 40 | { error( s1 + s2 ); } 41 | 42 | } // namespace ppp 43 | 44 | namespace ppp_ex { 45 | 46 | // Functions added here for the same purpose, more convenient: 47 | using namespace stdlib::hopefully_and_fail; 48 | 49 | } // namespace ppp_ex 50 | -------------------------------------------------------------------------------- /source/fix/output_of_implicit_wide_c_string.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // This is a fix for a defect in standard library, where an object that's implicitly 5 | // convertible to `char const*` /can/ be output to a narrow stream, but an object 6 | // that's implicitly convertible to `wchar_t const*` /cannot/ be output to a wide 7 | // stream (it's presented as a pointer value because the templated `operator<<` is 8 | // not considered by overload resolution). I reported the defect years ago, as of 9 | // 2017. As far as I know nothing happened with that defect report. 10 | // 11 | // STDLIB_NO_OUTPUT_OF_IMPLICIT_WIDE_C_STRING_FIX suppresses the fix. 12 | // 13 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 14 | 15 | #include // stdlib::ext::(ref_, ptr_) 16 | #include 17 | 18 | #ifndef STDLIB_NO_FIX_OF_OUTPUT_OF_IMPLICIT_WIDE_C_STRING 19 | #pragma push_macro( "REF_" ) 20 | #pragma push_macro( "PTR_" ) 21 | #undef REF_ 22 | #define REF_ ::stdlib::ext::ref_ 23 | #undef PTR_ 24 | #define PTR_ ::stdlib::ext::ptr_ 25 | 26 | namespace std { 27 | 28 | inline auto operator<< ( 29 | REF_>> stream, 30 | const PTR_ s 31 | ) 32 | -> stdlib::ext::ref_>> 33 | { return stream.write( s, char_traits::length( s ) ); } 34 | 35 | } // namespace std 36 | 37 | #pragma pop_macro( "PTR_" ) 38 | #pragma pop_macro( "REF_" ) 39 | #endif 40 | -------------------------------------------------------------------------------- /source/extension/version.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 5 | 6 | #include 7 | 8 | #ifndef STDLIB_COMPILER_SUPPORTS_CPP11 9 | # define STDLIB_COMPILER_SUPPORTS_CPP11 (__cplusplus >= 201103) 10 | #endif 11 | 12 | #ifndef STDLIB_COMPILER_SUPPORTS_CPP14 13 | # define STDLIB_COMPILER_SUPPORTS_CPP14 (__cplusplus >= 201402) 14 | #endif 15 | 16 | // With Visual C++ 2017 use `/std:c++latest` option to get C++17 lib support. 17 | #if !defined( STDLIB_COMPILER_SUPPORTS_CPP17 ) && defined( _MSVC_LANG ) 18 | # if _MSC_VER < 2000 && _MSVC_LANG > 201402 19 | # define STDLIB_COMPILER_SUPPORTS_CPP17 1 20 | // One must include ordinary but the impl is in namespace 21 | // "experimental", neither fish nor fowl; it's a special case. 22 | # define STDLIB_HOIST_UP_FILESYSTEM_NAMESPACE 23 | # endif 24 | #endif 25 | 26 | #ifndef STDLIB_COMPILER_SUPPORTS_CPP17 27 | # define STDLIB_COMPILER_SUPPORTS_CPP17 (__cplusplus > 201700) 28 | #endif 29 | 30 | #ifdef STDLIB_USE_EXPERIMENTAL_CPP17 31 | # define STDLIB_HOIST_UP_FILESYSTEM_NAMESPACE 32 | #else 33 | # define STDLIB_USE_EXPERIMENTAL_CPP17 0 34 | #endif 35 | 36 | #define STDLIB_HAS_CPP17_FEATURES \ 37 | (STDLIB_COMPILER_SUPPORTS_CPP17 || STDLIB_USE_EXPERIMENTAL_CPP17) 38 | 39 | namespace stdlib{ namespace ext{ namespace platform{ 40 | #ifdef _WIN32 41 | constexpr bool is_windows = true; 42 | #else 43 | constexpr bool is_windows = false; 44 | #endif 45 | }}} // namespace stdlibx::ext::platform 46 | -------------------------------------------------------------------------------- /source/extension/process_command_line.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // An UTF-8 alternative to just using the arguments of `main`. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | #include 9 | 10 | // For exposition only (each included header below includes this itself): 11 | #include 12 | 13 | #if defined( STDLIB_USE_CUSTOM_COMMAND_LINE_IMPL ) 14 | # include // Last fallback. 15 | #elif defined( _WIN32 ) 16 | # include 17 | #elif defined( __APPLE__ ) 18 | # include "TargetConditionals.h" 19 | # if defined( TARGET_IPHONE_SIMULATOR ) 20 | # error Process command line is not supported for Apple IPhone Simulator, sorry. 21 | # elif defined( TARGET_OS_IPHONE ) 22 | # error Process command line is not supported for Apple IPhone, sorry. 23 | # elif defined( TARGET_OS_MAC ) 24 | # error Process command line is not supported for your macOS, sorry. 25 | # else 26 | # error Process command line is not supported for this (unknown) Apple platform. 27 | # endif 28 | #elif defined( __linux__ ) 29 | # include 30 | #elif defined( __unix__ ) // all unices not caught above 31 | # error Process command line is not supported for non-Linux Unix, sorry. 32 | #elif defined( _POSIX_VERSION ) 33 | # error Process command line is not supported for general Posix, sorry. 34 | #else 35 | # error Unknown operating system / platform. 36 | #endif 37 | -------------------------------------------------------------------------------- /source/extension/char_path.declarations.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Best effort compatible-with-runtime-library path. 5 | // In Windows some result path items can be alternate short names, if that’s 6 | // available for the file system, unless the long path is all ASCII, in which 7 | // case it’s just returned as-is. 8 | // 9 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 10 | 11 | #include 12 | 13 | #include // stdlib::(ref_) 14 | #include 15 | #include // std::move 16 | 17 | namespace stdlib{ namespace ext{ 18 | using std::move; 19 | using std::string; 20 | using std::wstring; 21 | 22 | inline auto char_path_with_substitution( const bool substitution_allowed, wstring long_path ) 23 | -> string; 24 | 25 | inline auto char_path_with_substitution( const bool substitution_allowed, string long_utf8_path ) 26 | -> string; 27 | 28 | inline auto char_path( wstring long_path ) 29 | -> string 30 | { return char_path_with_substitution( true, move( long_path ) ); } 31 | 32 | inline auto char_path( string long_utf8_path ) 33 | -> string 34 | { return char_path_with_substitution( true, move( long_utf8_path ) ); } 35 | 36 | inline auto char_path_or_x( wstring long_path ) 37 | -> string 38 | { return char_path_with_substitution( false, move( long_path ) ); } 39 | 40 | inline auto char_path_or_x( string long_utf8_path ) 41 | -> string 42 | { return char_path_with_substitution( false, move( long_utf8_path ) ); } 43 | 44 | }} // namespace stdlib::ext 45 | -------------------------------------------------------------------------------- /source/_impl/windows_process_command_line/apiwrap.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include // stdlib::(hopefully, fail) 6 | #include // stdlib::(raw_array_, ptr_) 7 | #include // winapi::* 8 | #include // and 9 | 10 | #include // std::unique_ptr 11 | 12 | namespace stdlib{ namespace impl{ namespace apiwrap{ 13 | using std::unique_ptr; 14 | using namespace stdlib::ext::type_builders; 15 | using namespace stdlib::ext::hopefully_and_fail; 16 | 17 | inline auto command_line_ptr() 18 | -> ptr_ 19 | { return winapi::GetCommandLineW(); } 20 | 21 | inline void local_free( const ptr_ p ) { winapi::LocalFree( p ); } 22 | 23 | struct Command_line_args 24 | { 25 | using Ptr = unique_ptr< 26 | raw_array_< ptr_< wchar_t > >, 27 | ptr_< void(ptr_) > 28 | >; 29 | 30 | int count; 31 | Ptr items; 32 | 33 | Command_line_args( 34 | const ptr_ command_line = command_line_ptr() 35 | ) 36 | : items{ 37 | winapi::CommandLineToArgvW( command_line, &count ), 38 | &local_free 39 | } 40 | { 41 | hopefully( items != nullptr ) 42 | or fail( "stdlib::impl::apiwrap - API-function CommandLineToArgvW failed" ); 43 | } 44 | }; 45 | 46 | }}} // stdlib::impl::apiwrap 47 | -------------------------------------------------------------------------------- /source/fix/default_cpp_locale.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // The default locale needs to be set up 5 | // • to make wide streams work in Unix-land, and 6 | // • to make narrow character classification functions work in Windows. 7 | // 8 | // STDLIB_NO_FIX_OF_DEFAULT_CPP_LOCALE suppresses the locale auto-config. 9 | // 10 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 11 | 12 | #include // Do this first. 13 | #include 14 | 15 | #include 16 | #include 17 | 18 | #include //! 19 | 20 | namespace stdlib{ namespace impl{ namespace default_cpp_locale{ 21 | using std::locale; 22 | using std::numpunct; 23 | using stdlib::ext::ptr_; 24 | 25 | class Envelope 26 | { 27 | private: 28 | 29 | Envelope() noexcept 30 | { 31 | try 32 | { 33 | // The national locale supports UTF-8 in Unix-land. 34 | auto const& national_using_english_numbers = 35 | locale{ "" }.combine>( locale::classic() ); 36 | locale::global( national_using_english_numbers ); 37 | } 38 | catch( ... ) 39 | {} 40 | } 41 | 42 | ~Envelope() noexcept { locale::global( locale( "C" ) ); } 43 | 44 | public: 45 | static auto make_singleton() 46 | -> bool 47 | { 48 | static Envelope the_envelope; 49 | return true; 50 | } 51 | }; 52 | 53 | # ifndef STDLIB_NO_FIX_OF_DEFAULT_CPP_LOCALE 54 | const bool dummy = Envelope::make_singleton(); 55 | # endif 56 | 57 | }}} // namespace stdlib::impl::default_cpp_locale 58 | -------------------------------------------------------------------------------- /source/extension/math_constants.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Common math constants. 5 | // 6 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 7 | 8 | #include 9 | 10 | #include 11 | 12 | #ifndef STDLIB_NO_MATH_CONSTANTS 13 | namespace stdlib{ namespace ext{ 14 | inline namespace math { 15 | const auto e = M_E; // e 2.71828182845904523536 16 | const auto log2e = M_LOG2E; // log2(e) 1.44269504088896340736 17 | const auto log10e = M_LOG10E; // log10(e) 0.434294481903251827651 18 | const auto ln2 = M_LN2; // ln(2) 0.693147180559945309417 19 | const auto ln10 = M_LN10; // ln(10) 2.30258509299404568402 20 | const auto pi = M_PI; // pi 3.14159265358979323846 21 | // pi/2 M_PI_2 1.57079632679489661923 22 | // pi/4 M_PI_4 0.785398163397448309616 23 | // 1/pi M_1_PI 0.318309886183790671538 24 | // 2/pi M_2_PI 0.636619772367581343076 25 | const auto inv_sqrt_pi = M_2_SQRTPI/2; // 2/sqrt(pi) 1.12837916709551257390 26 | const auto sqrt2 = M_SQRT2; // sqrt(2) 1.41421356237309504880 27 | const auto inv_sqrt2 = M_SQRT1_2; // 1/sqrt(2) 0.707106781186547524401 28 | } // namespace math // 29 | }} // namespace stdlib::ext 30 | #endif 31 | -------------------------------------------------------------------------------- /source/c/math.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Common math functions. 5 | // Addditionally (M_*** is a de facto standard) defines the following constants: 6 | // 7 | // M_E stdlib::e e 2.71828182845904523536 8 | // M_LOG2E stdlib::log2e log2(e) 1.44269504088896340736 9 | // M_LOG10E stdlib::log10e log10(e) 0.434294481903251827651 10 | // M_LN2 lstdlib::ln2 n(2) 0.693147180559945309417 11 | // M_LN10 stdlib::ln10 ln(10) 2.30258509299404568402 12 | // M_PI stdlib::pi pi 3.14159265358979323846 13 | // M_PI_2 pi/2 1.57079632679489661923 14 | // M_PI_4 pi/4 0.785398163397448309616 15 | // M_1_PI 1/pi 0.318309886183790671538 16 | // M_2_PI 2/pi 0.636619772367581343076 17 | // M_2_SQRTPI 2*stdlib::inv_sqrt_pi 2/sqrt(pi) 1.12837916709551257390 18 | // M_SQRT2 stdlib::sqrt2 sqrt(2) 1.41421356237309504880 19 | // M_SQRT1_2 stdlib::inv_sqrt2 1/sqrt(2) 0.707106781186547524401 20 | // 21 | // E.g. see the MSDN article on “math constants” at 22 | // . 23 | // 24 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 25 | 26 | #include 27 | 28 | // At least with MSVC this works for defining M_PI etc. even if has 29 | // been previously included - the definitions are outside the normal guard. 30 | // But just to be on the safe safe, include the constant defs first. 31 | #include 32 | #include 33 | #include 34 | #include 35 | -------------------------------------------------------------------------------- /source/fix/math_constants_availability.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // E.g. see the MSDN article on “math constants” at 5 | // . 6 | // 7 | // STDLIB_NO_MATH_CONSTANTS suppresses the constant definitions. 8 | // 9 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 10 | 11 | #ifndef STDLIB_NO_MATH_CONSTANTS 12 | # undef __STRICT_ANSI__ // For g++ 13 | # undef _USE_MATH_DEFINES // Suppress sillywarning. 14 | # define _USE_MATH_DEFINES // M_PI etc. 15 | #endif 16 | 17 | // At least with MSVC this works for defining M_PI etc. even if has 18 | // been previously included - the definitions are outside the normal guard. 19 | #include 20 | #include 21 | 22 | #ifndef STDLIB_NO_MATH_CONSTANTS 23 | #ifndef M_PI // TODO: also handle non-macro 24 | #define _MATH_DEFINES_DEFINED // Avoid MSVC redefinition warning. 25 | #define M_E 2.71828182845904523536 // e 26 | #define M_LOG2E 1.44269504088896340736 // log2(e) 27 | #define M_LOG10E 0.434294481903251827651 // log10(e) 28 | #define M_LN2 0.693147180559945309417 // ln(2) 29 | #define M_LN10 2.30258509299404568402 // ln(10) 30 | #define M_PI 3.14159265358979323846 // pi 31 | #define M_PI_2 1.57079632679489661923 // pi/2 32 | #define M_PI_4 0.785398163397448309616 // pi/4 33 | #define M_1_PI 0.318309886183790671538 // 1/pi 34 | #define M_2_PI 0.636619772367581343076 // 2/pi 35 | #define M_2_SQRTPI 1.12837916709551257390 // 2/sqrt(pi) 36 | #define M_SQRT2 1.41421356237309504880 // sqrt(2) 37 | #define M_SQRT1_2 0.707106781186547524401 // 1/sqrt(2) 38 | #endif 39 | #endif 40 | -------------------------------------------------------------------------------- /source/filesystem.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // std::path class and supporting functions. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include // STDLIB_COMPILER_SUPPORTS_CPP17 8 | #include 9 | 10 | #include // For stdlib::char_path(path) 11 | #include // For STDLIB_FIX_GCC_U8PATH 12 | 13 | #if STDLIB_USE_EXPERIMENTAL_CPP17 14 | # include 15 | #elif STDLIB_COMPILER_SUPPORTS_CPP17 16 | # include 17 | #else 18 | # ifdef _MSC_VER 19 | # error " appears not available (try option `/std:c++latest`?)." 20 | # else 21 | # error " appears not available (try define STDLIB_USE_EXPERIMENTAL_CPP17?)." 22 | # endif 23 | #endif 24 | 25 | #ifdef STDLIB_HOIST_UP_FILESYSTEM_NAMESPACE 26 | namespace std { 27 | namespace filesystem { 28 | using namespace experimental::filesystem; 29 | } // namespace filesystem 30 | } // namespace std; 31 | #endif 32 | 33 | #if defined( STDLIB_FIX_GCC_U8PATH ) && defined( __GNUC__ ) && defined( _WIN32 ) 34 | namespace std{ namespace filesystem { 35 | inline auto u8path( string const& source ) 36 | -> path 37 | { return path{ ::stdlib::wide_from_utf8( source ) }; } 38 | 39 | inline auto u8path( char const* const source ) 40 | -> path 41 | { return u8path( string( source ) ); } 42 | }} // std::namespace filesystem 43 | #endif 44 | 45 | namespace stdlib{ namespace ext{ 46 | namespace fs = ::std::filesystem; 47 | 48 | // Best effort compatible-with-runtime-library path. 49 | 50 | inline auto char_path( ref_ path ) 51 | -> string 52 | { return char_path( path.native() ); } 53 | 54 | inline auto char_path_or_x( ref_ path ) 55 | -> string 56 | { return char_path_or_x( path.native() ); } 57 | 58 | }} // namespace stdlib::ext 59 | 60 | #include 61 | -------------------------------------------------------------------------------- /source/_impl/linux_process_command_line.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Implementation based on C code by blogger “Ivan”, ATTOW presented at 5 | // . 6 | // 7 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 8 | 9 | #ifndef __linux__ 10 | # error This file is only meaningful in Linux. 11 | #endif 12 | 13 | #include // stdlib::(hopefully, fail) 14 | #include // 15 | #include // stdlib::raw_array_ 16 | 17 | #include // std::replace 18 | #include 19 | #include 20 | 21 | namespace stdlib{ 22 | using std::ifstream; 23 | using std::getline; 24 | using std::replace; 25 | using std::string; 26 | using std::to_string; 27 | 28 | namespace impl { 29 | inline auto get_command_line_data() 30 | -> string 31 | { 32 | static const raw_array_ funcname = "stdlib::impl::get_command_line_data"; 33 | 34 | const string path = "/proc/self/cmdline"; // "self" provides getpid() 35 | ifstream f{ path }; 36 | hopefully( not f.fail() ) 37 | or fail( string() + funcname + " - failed to open “" + path + "”" ); 38 | string result; 39 | getline( f, result ) 40 | or fail( string() + funcname + " - failed to read “" + path + "”" ); 41 | return result; 42 | } 43 | } // namespace impl 44 | 45 | constexpr 46 | inline auto has_original_command_line() 47 | -> bool 48 | { return false; } 49 | 50 | inline auto process::command_line() 51 | -> string 52 | { return ""; } 53 | 54 | inline process::Command_line_args::Command_line_args() 55 | { 56 | const string s = impl::get_command_line_data(); 57 | int i = 0; 58 | for( char const* p = &s[0]; *p; p += strlen( p ) + 1 ) 59 | { 60 | items_.push_back( p ); 61 | } 62 | } 63 | 64 | } // namespace stdlib 65 | -------------------------------------------------------------------------------- /source/_impl/windows_char_path/api.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include // ptr_ 6 | 7 | #include // winapi::(DWord, max_path_length, ...) 8 | #include // winapi::(max_path_length, cp_acp, ...) 9 | 10 | namespace stdlib{ namespace impl{ namespace winapi{ 11 | 12 | const DWord wc_no_best_fit_chars = 0x00000400; // From . 13 | 14 | struct FileTime 15 | { 16 | DWord dwLowDateTime; 17 | DWord dwHighDateTime; 18 | }; 19 | 20 | struct Win32_find_data 21 | { 22 | DWord dwFileAttributes; 23 | FileTime ftCreationTime; 24 | FileTime ftLastAccessTime; 25 | FileTime ftLastWriteTime; 26 | DWord nFileSizeHigh; 27 | DWord nFileSizeLow; 28 | DWord dwReserved0; 29 | DWord dwReserved1; 30 | wchar_t cFileName[max_path_length]; 31 | wchar_t cAlternateFileName[14]; 32 | }; 33 | 34 | extern "C" 35 | auto __stdcall GetShortPathNameW( 36 | ptr_ lpszLongPath, 37 | ptr_ lpszShortPath, 38 | DWord cchBuffer 39 | ) -> DWord ; 40 | 41 | extern "C" 42 | auto __stdcall FindFirstFileW( 43 | ptr_ lpFileName, 44 | ptr_ lpFindFileData 45 | ) -> Handle; 46 | 47 | extern "C" 48 | auto __stdcall FindClose( Handle hFindFile ) 49 | -> Bool; 50 | 51 | extern "C" 52 | auto __stdcall WideCharToMultiByte( 53 | UInt CodePage, 54 | DWord dwFlags, 55 | ptr_ lpWideCharStr, 56 | int cchWideChar, 57 | ptr_ lpMultiByteStr, 58 | int cbMultiByte, 59 | ptr_ lpDefaultChar, 60 | ptr_ lpUsedDefaultChar 61 | ) -> int; 62 | 63 | }}} // namespace stdlib::impl::winapi 64 | -------------------------------------------------------------------------------- /source/extension/size_functions.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Size types and signed result size functions. 5 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 6 | 7 | #include 8 | 9 | #include // std::array 10 | #include // std::bitset 11 | #include // std::distance 12 | #include // std::remove_reference_t 13 | #include // std::(begin, end) 14 | #include // size_t, ptrdiff_t, Size, Index 15 | #include // stdlib::(array_of_, raw_array_of_) 16 | 17 | #define STDLIB_ARRAY_SIZE( a ) ::stdlib::Array_size_>::value 18 | 19 | namespace stdlib{ namespace ext{ 20 | using std::begin; 21 | using std::bitset; 22 | using std::distance; 23 | using std::end; 24 | using std::remove_reference_t; 25 | 26 | template< class > struct Array_size_; 27 | 28 | template< class Item, size_t n > 29 | struct Array_size_ < raw_array_of_ > 30 | { 31 | static constexpr Size value = n; 32 | }; 33 | 34 | template< class Item, size_t n > 35 | struct Array_size_ < array_of_ > 36 | { 37 | static constexpr Size value = n; 38 | }; 39 | 40 | template< size_t n > 41 | struct Array_size_ < bitset< n > > 42 | { 43 | static constexpr Size value = n; 44 | }; 45 | 46 | // As of C++14 this won't be constexpr for an argument that is a formal 47 | // argument of the calling function. This is the same issue as with 48 | // C++17 std::size, at least in clang ATTOW. Hence the macro given above. 49 | 50 | template< class Result, class Type > 51 | constexpr inline auto array_size_( Type const& a ) 52 | -> Result 53 | { return static_cast( Array_size_>::value ); } 54 | 55 | template< class Type > 56 | constexpr inline auto array_size( Type const& a ) 57 | -> Size 58 | { return array_size_( a ); } 59 | 60 | template< class Collection > 61 | auto n_items_of( Collection const& c ) 62 | -> Size 63 | { return distance( begin( c ), end( c ) ); } 64 | 65 | template< size_t n > 66 | auto n_items_of( bitset const& bits ) 67 | -> Size 68 | { return bits.count(); } 69 | 70 | }} // namespace stdlib::ext 71 | -------------------------------------------------------------------------------- /source/_impl/windows_console_io/Wide_console_input_buffer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include // assert 6 | #include // ptrdiff_t 7 | #include 8 | #include // std::(begin, end) 9 | #include // std::basic_streambuf 10 | 11 | #include // ptr_, array_of_ 12 | #include // general_buffer_size 13 | #include // apiwrap::* 14 | 15 | namespace stdlib{ namespace impl{ namespace windows_console_io{ 16 | using std::basic_streambuf; 17 | using std::begin; 18 | using std::end; 19 | 20 | class Wide_console_input_buffer 21 | : public basic_streambuf 22 | { 23 | static constexpr Size buffer_size = general_buffer_size; 24 | using Base = basic_streambuf; 25 | using Traits = traits_type; 26 | 27 | array_of_ buffer_; 28 | 29 | Wide_console_input_buffer( Wide_console_input_buffer const& ) = delete; 30 | 31 | auto readbuf_start() const -> ptr_ { return eback(); } 32 | auto readbuf_beyond() const -> ptr_ { return egptr(); } 33 | 34 | auto read_position() const -> ptr_ { return gptr(); } 35 | 36 | void advance_read_position( const int n ) { gbump( n ); } 37 | 38 | protected: 39 | auto pbackfail( const int_type ch ) 40 | -> int_type 41 | override 42 | { (void) ch; return traits_type::eof(); } // TODO: 43 | 44 | auto underflow() // Called by uflow() 45 | -> int_type 46 | override 47 | { 48 | assert( read_position() == readbuf_beyond() ); 49 | 50 | const auto p_start = readbuf_start(); 51 | const Size n = apiwrap::get_text_from_console( p_start, buffer_size ); 52 | 53 | setg( p_start, p_start, p_start + n ); // first, next, last 54 | return (n == 0? Traits::eof() : Traits::to_int_type( *read_position() )); 55 | } 56 | 57 | public: 58 | Wide_console_input_buffer() 59 | { 60 | const ptr_ buffer_start = buffer_.data(); 61 | setg( buffer_start, buffer_start, buffer_start ); // first, next, last 62 | } 63 | }; 64 | }}} // namespace stdlib::impl::windows_console_io 65 | -------------------------------------------------------------------------------- /source/extension/utf8_conversion.hpp: -------------------------------------------------------------------------------- 1 | // Source encoding: utf-8 with BOM ∩ 2 | #pragma once 3 | 4 | #include 5 | 6 | #include // std::(min) 7 | #include // std::(string, wstring) 8 | 9 | #include 10 | #include 11 | #include 12 | #include // Size, Index 13 | #include // or 14 | 15 | namespace stdlib{ namespace ext{ 16 | using std::min; 17 | using std::string; 18 | using std::wstring; 19 | 20 | inline namespace utf8_conversion { 21 | inline auto utf8_from( const wstring& s ) 22 | -> string 23 | { 24 | string result; 25 | Streaming_wide_to_byte_converter converter; 26 | 27 | const Size n = s.length(); 28 | for( Index read_pos = 0; read_pos < n or converter.n_buffered() > 0; ) 29 | { 30 | char out_buffer[stdlib::impl::converter_buffer_size]; 31 | const Size max_n_bytes = array_size( out_buffer ); 32 | 33 | const Size n_available_wchars = n - read_pos; 34 | const Size max_n_wchars = min( 35 | n_available_wchars, converter.available_space() 36 | ); 37 | 38 | converter.add( max_n_wchars, s.data() + read_pos ); 39 | const Size n_bytes = converter.convert_into( out_buffer, max_n_bytes ); 40 | result.append( out_buffer, n_bytes ); 41 | 42 | read_pos += max_n_wchars; 43 | } 44 | return result; 45 | } 46 | 47 | inline auto wide_from_utf8( string const& s ) 48 | -> wstring 49 | { 50 | wstring result; 51 | Streaming_byte_to_wide_converter converter; 52 | 53 | const Size n = s.length(); 54 | for( Index read_pos = 0; read_pos < n or converter.n_buffered() > 0; ) 55 | { 56 | wchar_t out_buffer[stdlib::impl::converter_buffer_size]; 57 | const Size max_n_wchars = array_size( out_buffer ); 58 | 59 | const Size n_available_bytes = n - read_pos; 60 | const Size max_n_bytes = min( 61 | n_available_bytes, converter.available_space() 62 | ); 63 | 64 | converter.add( max_n_bytes, s.data() + read_pos ); 65 | const Size n_wchars = converter.convert_into( out_buffer, max_n_wchars ); 66 | result.append( out_buffer, n_wchars ); 67 | 68 | read_pos += max_n_bytes; 69 | } 70 | return result; 71 | } 72 | } // namespace utf8_conversion 73 | 74 | }} // namespace stdlib::ext 75 | -------------------------------------------------------------------------------- /examples/c++17/string_view.cpp: -------------------------------------------------------------------------------- 1 | // Source encoding: utf-8 with BOM ∩ 2 | // 3 | // For Visual C++ 2017 and earlier compile with option “/std::c++latest”. 4 | // For g++, “g++ string_view.cpp -D STDLIB_USE_EXPERIMENTAL_CPP17”. 5 | // 6 | // Based on an example whose behavior I couldn't reproduce, with unintended 7 | // Undefined Behavior, at . 8 | // 9 | // The machinery at the start here is just to see a concrete example of 10 | // how std::string does dynamic allocations. It’s possibly quite misleading 11 | // because the custom allocator may prevent the compiler from completely 12 | // optimizing away these allocations! Be that as it may, here goes: 13 | 14 | #include 15 | #include 16 | using namespace std; 17 | 18 | 19 | //---------------------------------------------------------------------------- 20 | // Allocation tracking machinery: 21 | 22 | namespace g{ 23 | int allocations[1000] = {}; 24 | int n_allocations = 0; 25 | bool track_allocations = true; 26 | } // namespace g 27 | 28 | template< class T > 29 | struct Tracking_allocator 30 | : allocator< T > 31 | { 32 | template< class U > struct rebind { using other = Tracking_allocator; }; 33 | 34 | auto allocate( size_t const n, void const* const hint = nullptr ) 35 | -> T* 36 | { 37 | (void) hint; 38 | if( g::track_allocations ) 39 | { 40 | g::allocations[g::n_allocations++] = n; 41 | } 42 | return reinterpret_cast( malloc( n*sizeof( T ) ) ); 43 | } 44 | 45 | void deallocate( T* const p, size_t const n ) 46 | { 47 | (void) n; 48 | free( p ); 49 | } 50 | 51 | }; 52 | 53 | using String = basic_string, Tracking_allocator>; 54 | #ifdef USE_STRING 55 | using S = String; 56 | #else 57 | using S = string_view; // Has no allocator, cause is has no allocations. 58 | #endif 59 | 60 | //---------------------------------------------------------------------------- 61 | // Main example code: 62 | 63 | auto compare( S const& s1, S const& s2 ) 64 | -> bool 65 | { 66 | if( s1 != s2 ) 67 | { 68 | cout << '\"' << s1 << "\" does not match \"" << s2 << "\"\n"; 69 | return false; 70 | } 71 | return true; 72 | } 73 | 74 | auto main() 75 | -> int 76 | { 77 | String const s = "this is my input string"; 78 | 79 | compare( s, "this is the first test string" ); 80 | compare( s, "this is the second test string" ); 81 | compare( s, "this is the third test string, it's a bit longer than the earlier two" ); 82 | 83 | g::track_allocations = false; 84 | cout << g::n_allocations << " dynamic allocation(s)"; 85 | if( g::n_allocations > 0 ) 86 | { 87 | cout << " of size(s) "; 88 | for( int i = 0; i < g::n_allocations; ++i ) 89 | { 90 | if( i > 0 ) 91 | { 92 | cout << ", "; 93 | } 94 | cout << g::allocations[i]; 95 | } 96 | } 97 | cout << "." << endl; 98 | } 99 | -------------------------------------------------------------------------------- /source/_impl/windows_console_io/api.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include // ptr_ 6 | 7 | #include // winapi::(DWord, ...) 8 | #include // winapi::(max_path_length, cp_utf8, ...) 9 | 10 | namespace stdlib{ namespace impl{ namespace winapi{ 11 | enum: DWord 12 | { 13 | std_input_handle = DWord( -10 ), 14 | std_output_handle = DWord( -11 ), 15 | std_error_handle = DWord( -12 ) 16 | }; 17 | 18 | enum: DWord 19 | { 20 | enable_virtual_terminal_processing = 0x0004 21 | }; 22 | 23 | enum: DWord 24 | { 25 | generic_read = (0x80000000L), 26 | generic_write = (0x40000000L), 27 | generic_execute = (0x20000000L), 28 | generic_all = (0x10000000L) // (sic) 29 | }; 30 | 31 | enum: DWord 32 | { 33 | create_new = 1, 34 | create_always = 2, 35 | open_existing = 3, 36 | open_always = 4, 37 | truncate_existing = 5 38 | }; 39 | 40 | using Security_attributes = void; // We don't need security attributes. 41 | 42 | extern "C" 43 | auto __stdcall CreateFileW( 44 | ptr_ lpFileName, 45 | DWord dwDesiredAccess, 46 | DWord dwShareMode, 47 | ptr_ lpSecurityAttributes, 48 | DWord dwCreationDisposition, 49 | DWord dwFlagsAndAttributes, 50 | Handle hTemplateFile 51 | ) -> Handle; 52 | 53 | extern "C" 54 | auto __stdcall GetConsoleMode( 55 | Handle hConsoleHandle, 56 | ptr_ lpMode 57 | ) -> Bool; 58 | 59 | extern "C" 60 | auto __stdcall GetStdHandle( DWord nStdHandle ) 61 | -> Handle; 62 | 63 | extern "C" 64 | auto __stdcall ReadConsoleW( 65 | Handle hConsoleInput, 66 | ptr_ lpBuffer, 67 | DWord nNumberOfCharsToRead, 68 | ptr_ lpNumberOfCharsRead, 69 | ptr_ pInputControl 70 | ) -> Bool; 71 | 72 | extern "C" 73 | auto __stdcall SetConsoleMode( 74 | Handle hConsoleHandle, 75 | DWord dwMode 76 | ) -> Bool; 77 | 78 | extern "C" 79 | auto __stdcall WideCharToMultiByte( 80 | UInt CodePage, 81 | DWord dwFlags, 82 | ptr_ lpWideCharStr, 83 | int cchWideChar, 84 | ptr_ lpMultiByteStr, 85 | int cbMultiByte, 86 | ptr_ lpDefaultChar, 87 | ptr_ lpUsedDefaultChar 88 | ) -> int; 89 | 90 | extern "C" 91 | auto __stdcall WriteConsoleW( 92 | Handle hConsoleOutput, 93 | ptr_ lpBuffer, 94 | DWord nNumberOfCharsToWrite, 95 | ptr_ lpNumberOfCharsWritten, 96 | ptr_ lpReserved 97 | ) -> Bool; 98 | }}} // namespace stdlib::impl::winapi 99 | -------------------------------------------------------------------------------- /source/extension/ascii.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Names for special ASCII characters. 5 | // 6 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 7 | 8 | #include 9 | 10 | namespace stdlib{ namespace ext{ namespace ascii { 11 | char const null = '\0'; // '\0' 0x00 12 | char const bell = '\a'; // '\a' 0x07, ^G 13 | char const backspace = '\b'; // '\b' 0x07, ^H 14 | char const tab = '\t'; // '\t' 0x08, ^I, horizontal tab 15 | char const linefeed = '\n'; // '\n' 0x09, ^J 16 | char const vtab = '\v'; // '\v' 0x0A, ^K 17 | char const formfeed = '\f'; // '\f' 0x0B, ^L 18 | char const enter = '\r'; // '\r' 0x0C, ^M 19 | char const xon = '\x11'; // 0x11, ^Q, "continue" 20 | char const xoff = '\x13'; // 0x13, ^S, "stop" 21 | char const end_of_text = '\x1A'; // 0x1A, ^Z, non-std MS meaning. 22 | char const escape = '\x1B'; // 0x1B 23 | char const del = '\x7F'; // 0x7F 24 | 25 | // Abbreviations as per ASCII 67: 26 | char const NUL = null; 27 | char const BEL = bell; 28 | char const BS = backspace; 29 | char const HT = tab; // “Horizontal tab” 30 | char const LF = linefeed; 31 | char const VT = vtab; // “Vertical tab” 32 | char const FF = formfeed; 33 | char const CR = enter; // “Carriage return” 34 | char const DC1 = xon; // “Device control 1” 35 | char const DC3 = xoff; // “Device control 3” 36 | char const SUB = end_of_text; // “Substitute”, but see below! 37 | char const ESC = escape; 38 | char const DEL = del; // “Delete” 39 | 40 | // ASCII DEL, code 0x7F = 127, “delete”, is used in this library as a 41 | // replacement for encoding errors or unrepresentable code point. 42 | // 43 | // ASCII has a character dedicated to the purpose: SUB “substitute”, code 26, 44 | // ^Z. But in Windows ^Z is used as an EOF marker for text streams. So ^Z as 45 | // replacement is not usable in Windows, i.e. it's not a general solution. 46 | // 47 | // Unicode, an extension of ASCII, also has its own character dedicated to 48 | // the purpose, namely code U+FFFD “replacement character”. It translates to 49 | // at least two UTF-8 bytes so it's not trivial to check for. And it can't be 50 | // represented in simple single byte encodings such as codepage 437, so it's 51 | // not usable in single byte encodings, i.e. it's not a general solution. 52 | char const bad_char = del; 53 | 54 | template< class Number > 55 | inline auto contains( const Number v ) 56 | -> bool 57 | { return (0 <= v and v <= 127); } 58 | 59 | template< class It > 60 | inline auto contains_all( const It start, const It beyond ) 61 | -> bool 62 | { 63 | for( It it = start; it != beyond; ++it ) 64 | { 65 | if( not ascii::contains( *it ) ) { return false; } 66 | } 67 | return true; 68 | } 69 | }}} // namespace stdlib::ext::ascii 70 | -------------------------------------------------------------------------------- /source/extension/process_command_line.declarations.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include // stdlib::(Size, Index) 6 | #include // stdlib::ref_ 7 | #include // stdlib::platform::is_windows 8 | 9 | #include // not 10 | 11 | #include // std::move 12 | #include // std::vector 13 | #include // std::string 14 | 15 | namespace stdlib{ namespace ext{ namespace process{ 16 | using std::move; 17 | using std::string; 18 | using std::vector; 19 | 20 | constexpr 21 | inline auto has_original_command_line() // Platform-dependent. 22 | -> bool; 23 | 24 | // UTF-8. Original command line as passed to the process, e.g. in Windows. 25 | // Empty on systems with no such, i.e. where `not has_original_command_line()`. 26 | inline auto command_line() // Platform-dependent. 27 | -> string; 28 | 29 | // UTF-8 encoded command line arguments. 30 | class Command_line_args 31 | { 32 | Command_line_args( const int n, ptr_> args ) 33 | : items_( args, args + n ) 34 | {} 35 | 36 | protected: 37 | vector items_; 38 | string empty_item_; 39 | 40 | public: 41 | auto size() const -> Size { return items_.size(); } 42 | auto begin() const { return items_.begin(); } 43 | auto end() const { return items_.end(); } 44 | 45 | // Number of args after the command verb. 46 | auto count() const -> Size { return size() - 1; } 47 | 48 | auto operator[]( Index const i ) const 49 | -> ref_ 50 | { return (0 <= i and i < size()? items_[i] : empty_item_); } 51 | 52 | static auto from_os_or_else_from( 53 | const int argc, // Pass 1st argument of `main` here. 54 | const ptr_> argv // Pass 2nd argument of `main` here. 55 | ) -> Command_line_args 56 | { 57 | // May be modified later to include other ungood-main-args platforms. 58 | return ( 59 | platform::is_windows? Command_line_args{} 60 | : Command_line_args{ argc, argv } 61 | ); 62 | } 63 | 64 | inline Command_line_args(); // Platform-dependent. 65 | }; 66 | 67 | // `main`-arguments style argument pointers for e.g. use of `getopt`. 68 | class Command_argv_array 69 | : private Command_line_args 70 | { 71 | vector> pointers_; 72 | 73 | public: 74 | explicit operator bool() const { return true; } // For C++14 `if` as `with`. 75 | 76 | auto argc() -> int { return size(); } 77 | auto argv() -> ptr_> { return &pointers_[0]; } 78 | 79 | Command_argv_array( Command_line_args args = {} ) 80 | : Command_line_args{ move( args ) } 81 | { 82 | for( ref_ s : Command_line_args::items_ ) 83 | { 84 | pointers_.push_back( &s[0] ); 85 | } 86 | pointers_.push_back( nullptr ); 87 | } 88 | }; 89 | 90 | }}} // namespace stdlib::ext::process 91 | -------------------------------------------------------------------------------- /source/extension/type_builders.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include 6 | 7 | #include // stdlib::Size 8 | 9 | #include // std::array 10 | #include // std::(make_*, add_*, remove_*) 11 | 12 | namespace stdlib{ namespace ext{ 13 | namespace impl { 14 | using std::add_const_t; 15 | using std::array; 16 | using std::make_signed_t; 17 | using std::make_unsigned_t; 18 | using std::remove_const_t; 19 | using std::remove_extent_t; 20 | using std::remove_pointer_t; 21 | using std::remove_reference_t; 22 | 23 | //--------------------------------------------------- 24 | 25 | template< class Some_type > 26 | using type_ = Some_type; 27 | 28 | 29 | //--------------------------------------------------- 30 | 31 | // Note: the more safe standard library converters such as std::add_pointer_t 32 | // are not used for commented builders because they would prevent template 33 | // argument deduction. The basic builders defined here are just names for the 34 | // conventional way of writing e.g. formal argument types. As such they carry 35 | // the same risk of unintended type result as the raw operator notation does, 36 | // but they have advantages such as supporting uniform `const` first notation, 37 | // more generally read-left-to-right declarations, and being self-descriptive. 38 | 39 | template< class Some_type > 40 | using ref_ = Some_type&; // std::add_lvalue_reference_t; 41 | 42 | template< class Some_reference_type > 43 | using unref_ = std::remove_reference_t; 44 | 45 | template< class Some_type > 46 | using ptr_ = Some_type*; // std::add_pointer_t; 47 | 48 | template< class Some_pointer_type > 49 | using unptr_ = std::remove_pointer_t; 50 | 51 | template< class Integer > 52 | using signed_ = std::make_signed_t< Integer >; 53 | 54 | template< class Integer > 55 | using unsigned_ = std::make_unsigned_t< Integer >; 56 | 57 | template< class Some_type > 58 | using const_ = std::add_const_t< Some_type >; 59 | 60 | template< class Some_type > 61 | using unconst_ = std::remove_const_t< Some_type >; 62 | 63 | 64 | //--------------------------------------------------- 65 | 66 | template< class Some_type > 67 | using temp_ref_ = Some_type&&; // std::add_rvalue_reference_t; 68 | 69 | template< class Some_type > 70 | using forwarding_ref_ = Some_type&&; // Also known as a “universal reference”. 71 | 72 | template< size_t n, class Item > 73 | using array_of_ = array; 74 | 75 | template< class Item > 76 | using raw_array_ = Item[]; 77 | 78 | template< size_t n, class Item > 79 | using raw_array_of_ = Item[n]; 80 | 81 | template< class Some_array_type > 82 | using item_type_of_ = remove_extent_t; 83 | 84 | } // namespace impl 85 | 86 | inline namespace type_builders { 87 | using impl::type_; 88 | 89 | using impl::ref_; 90 | using impl::unref_; 91 | using impl::ptr_; 92 | using impl::unptr_; 93 | using impl::signed_; 94 | using impl::unsigned_; 95 | using impl::const_; 96 | using impl::unconst_; 97 | 98 | using impl::temp_ref_; 99 | using impl::forwarding_ref_; 100 | using impl::array_of_; 101 | using impl::raw_array_; 102 | using impl::raw_array_of_; 103 | using impl::item_type_of_; 104 | } // inline namespace type_builders 105 | }} // namespace stdlib::ext 106 | 107 | -------------------------------------------------------------------------------- /source/_impl/windows_console_io/apiwrap.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include // std::remove, std::equal 6 | #include // ptrdiff_t 7 | 8 | #include // stdlib::ascii::end_of_text 9 | #include // stdlib::(Size, Index) 10 | #include // winapi::* 11 | #include // and 12 | 13 | namespace stdlib{ namespace impl{ namespace apiwrap{ 14 | using std::equal; 15 | using std::remove; 16 | using namespace stdlib::ext; 17 | 18 | //inline auto input_stream_handle() 19 | // -> winapi::Handle 20 | //{ 21 | // static winapi::Handle const the_handle = 22 | // winapi::GetStdHandle( winapi::std_input_handle ); 23 | // return the_handle; 24 | //} 25 | 26 | //inline auto output_stream_handle() 27 | // -> winapi::Handle 28 | //{ 29 | // static winapi::Handle const the_handle = 30 | // winapi::GetStdHandle( winapi::std_output_handle ); 31 | // return the_handle; 32 | //} 33 | 34 | //inline auto error_stream_handle() 35 | // -> winapi::Handle 36 | //{ 37 | // static winapi::Handle const the_handle = 38 | // winapi::GetStdHandle( winapi::std_error_handle ); 39 | // return the_handle; 40 | //} 41 | 42 | inline auto console_input_handle() 43 | -> winapi::Handle 44 | { 45 | static const winapi::Handle the_handle = winapi::CreateFileW( 46 | L"CONIN$", winapi::generic_read, 0, nullptr, winapi::open_existing, 0, 0 47 | ); 48 | return the_handle; 49 | } 50 | 51 | inline auto console_output_handle() 52 | -> winapi::Handle 53 | { 54 | static const winapi::Handle the_handle = winapi::CreateFileW( 55 | L"CONOUT$", winapi::generic_write, 0, nullptr, winapi::open_existing, 0, 0 56 | ); 57 | return the_handle; 58 | } 59 | 60 | inline auto enable_ansi_escape_codes( const winapi::Handle stream_handle ) 61 | -> winapi::DWord // original console mode 62 | { 63 | const winapi::DWord ansi_escape_codes_flag = 64 | winapi::enable_virtual_terminal_processing; 65 | 66 | winapi::DWord original_mode = 0; 67 | winapi::GetConsoleMode( stream_handle, &original_mode ); 68 | winapi::SetConsoleMode( stream_handle, original_mode | ansi_escape_codes_flag ); 69 | return original_mode; 70 | } 71 | 72 | // Each `\r\n` is translated to just `\n`. I.e. the last returned text chunk from 73 | // a typed in line is terminated with L'\n'. Exception: a line consisting of only 74 | // ^Z, ASCII 26, is treated as zero bytes read, signaling EOF to a C++ iostream. 75 | inline auto get_text_from_console( const ptr_ buffer, const Size buffer_size ) 76 | -> Size 77 | { 78 | winapi::DWord n_read = 0; 79 | const bool success = !!winapi::ReadConsoleW( 80 | console_input_handle(), 81 | buffer, static_cast( buffer_size ), &n_read, nullptr 82 | ); 83 | if( !success ) 84 | { 85 | return 0; 86 | } 87 | const auto end = remove( buffer, buffer + n_read, L'\r' ); 88 | const Size n = end - buffer; 89 | static const raw_array_of_<2, wchar_t> eot_line = { wchar_t( ascii::end_of_text ), L'\n' }; 90 | return (n == 2 and equal( buffer, buffer + 2, eot_line )? 0 : n); 91 | } 92 | 93 | // Each `\n` is translated to `\r\n` down in the WriteConsoleW code (or "as-if"). 94 | inline auto put_text_to_console( const ptr_ buffer, const Size buffer_size ) 95 | -> Size 96 | { 97 | winapi::DWord n = 0; 98 | const bool success = !!winapi::WriteConsoleW( 99 | console_output_handle(), 100 | buffer, static_cast( buffer_size ), &n, nullptr 101 | ); 102 | if( !success ) 103 | { 104 | return 0; 105 | } 106 | return n; 107 | } 108 | }}} // namespace stdlib::impl::apiwrap 109 | -------------------------------------------------------------------------------- /source/extension/Streaming_byte_to_wide_converter.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include 6 | 7 | #include // std::copy 8 | #include // assert 9 | #include // std::(begin, end) 10 | 11 | #include // ascii::bad_char 12 | #include // stdlib::(Codecvt, Codecvt_result) 13 | #include // stdlib::(Size, Index) 14 | #include // stdlib::(ptr_, raw_array_of_) 15 | #include 16 | 17 | namespace stdlib{ namespace ext{ 18 | using std::begin; 19 | using std::copy; 20 | using std::end; 21 | 22 | class Streaming_byte_to_wide_converter 23 | { 24 | public: 25 | static constexpr Size in_buf_size = stdlib::impl::converter_buffer_size; 26 | 27 | private: 28 | Codecvt codecvt_{}; 29 | Codecvt_state conversion_state_{}; // mb_state 30 | array_of_ in_buf_; 31 | Size n_buffered_ = 0; 32 | 33 | auto start_of_buffer() -> ptr_ { return in_buf_.data(); } 34 | auto put_position() -> ptr_ { return start_of_buffer() + n_buffered_; } 35 | auto beyond_buffer() -> ptr_ { return start_of_buffer() + in_buf_.size(); } 36 | 37 | public: 38 | auto n_buffered() const -> Size { return n_buffered_; } 39 | auto available_space() const -> Size { return in_buf_size - n_buffered_; } 40 | 41 | void add( 42 | const Size n, 43 | const ptr_ chars 44 | ) 45 | { 46 | assert( n <= available_space() ); 47 | copy( chars, chars + n, put_position() ); 48 | n_buffered_ += n; 49 | } 50 | 51 | auto convert_into( 52 | const ptr_ result, 53 | const Size result_size 54 | ) -> Size 55 | { 56 | ptr_ p_next_in = start_of_buffer(); 57 | ptr_ p_next_out = result; 58 | 59 | for( ;; ) 60 | { 61 | const auto p_start_in = p_next_in; 62 | const auto p_start_out = p_next_out; 63 | const auto result_code = static_cast( codecvt_.in( 64 | conversion_state_, 65 | p_start_in, put_position(), p_next_in, // begin, end, beyond processed 66 | p_start_out, result + result_size, p_next_out // begin, end, beyond processed 67 | ) ); 68 | 69 | switch( result_code ) 70 | { 71 | case Codecvt::ok: 72 | case Codecvt::partial: 73 | case Codecvt::noconv: 74 | { 75 | copy>( p_next_in, put_position(), start_of_buffer() ); 76 | n_buffered_ = put_position() - p_next_in; 77 | return p_next_out - result; 78 | } 79 | 80 | case Codecvt::error: 81 | { 82 | *p_next_out++ = static_cast( ascii::bad_char ); 83 | // The Holy Standard (C++14) declares, in its §22.4.1.4.2/2: 84 | // “[the do_in function] Stops if it encounters a character it cannot convert. 85 | // It always leaves the from_next and to_next pointers pointing one beyond the 86 | // last element successfully converted.” But MSVC 2017 moves it one more byte, 87 | // which is practical but non-conforming behavior. So, don't do it for MSVC: 88 | #if !defined( _MSC_VER ) // TODO: Replace with check of behavior. 89 | ++p_next_in; 90 | #endif 91 | break; // p_next_in points past the offending byte. 92 | } 93 | 94 | default: 95 | { 96 | assert(( "Should never get here.", false )); throw 0; 97 | break; 98 | } 99 | } 100 | } 101 | } 102 | }; 103 | 104 | }} // namespace stdlib::ext 105 | -------------------------------------------------------------------------------- /source/extension/Streaming_wide_to_byte_converter.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include 6 | 7 | #include // std::copy 8 | #include // assert 9 | 10 | #include // ascii::bad_char 11 | #include // stdlib::(Codecvt, Codecvt_result) 12 | #include // stdlib::(Size, Index) 13 | #include // stdlib::(ptr_, raw_array_of_) 14 | #include 15 | 16 | namespace stdlib{ namespace ext{ 17 | using std::begin; 18 | using std::copy; 19 | using std::end; 20 | 21 | class Streaming_wide_to_byte_converter 22 | { 23 | public: 24 | static constexpr Size in_buf_size = stdlib::impl::converter_buffer_size; 25 | 26 | private: 27 | Codecvt codecvt_{}; 28 | Codecvt_state conversion_state_{}; // mb_state 29 | array_of_ in_buf_; 30 | Size n_in_buffered_ = 0; 31 | 32 | auto start_of_in_buffer() 33 | -> ptr_ 34 | { return in_buf_.data(); } 35 | 36 | auto put_in_position() 37 | -> ptr_ 38 | { return start_of_in_buffer() + n_in_buffered_; } 39 | 40 | auto beyond_in_buffer() 41 | -> ptr_ 42 | { return start_of_in_buffer() + in_buf_.size(); } 43 | 44 | public: 45 | auto n_buffered() const 46 | -> Size 47 | { return n_in_buffered_; } 48 | 49 | auto available_space() const 50 | -> Size 51 | { return in_buf_size - n_in_buffered_; } 52 | 53 | void add( 54 | const Size n, 55 | const ptr_ chars 56 | ) 57 | { 58 | assert( n <= available_space() ); 59 | copy( chars, chars + n, put_in_position() ); 60 | n_in_buffered_ += n; 61 | } 62 | 63 | auto convert_into( 64 | const ptr_ result, 65 | const Size result_size 66 | ) 67 | -> Size 68 | { 69 | ptr_ p_next_in = start_of_in_buffer(); 70 | ptr_ p_next_out = result; 71 | 72 | for( ;; ) 73 | { 74 | const auto p_start_in = p_next_in; 75 | const auto p_start_out = p_next_out; 76 | const auto result_code = static_cast( codecvt_.out( 77 | conversion_state_, 78 | p_start_in, put_in_position(), p_next_in, // begin, end, beyond processed 79 | p_start_out, result + result_size, p_next_out // begin, end, beyond processed 80 | ) ); 81 | 82 | switch( result_code ) 83 | { 84 | case Codecvt::ok: 85 | case Codecvt::partial: 86 | case Codecvt::noconv: 87 | { 88 | copy>( 89 | p_next_in, put_in_position(), // from 90 | start_of_in_buffer() // to 91 | ); 92 | n_in_buffered_ = put_in_position() - p_next_in; 93 | return p_next_out - result; 94 | } 95 | 96 | case Codecvt::error: 97 | { 98 | *p_next_out++ = ascii::bad_char; 99 | // The Holy Standard (C++14) declares, in its §22.4.1.4.2/2: 100 | // “[the do_out function] Stops if it encounters a character it cannot convert. 101 | // It always leaves the from_next and to_next pointers pointing one beyond the 102 | // last element successfully converted.” But MSVC 2017 moves it one more unit, 103 | // which is practical but non-conforming behavior. So, don't do it for MSVC: 104 | #if !defined( _MSC_VER ) // TODO: Replace with check of behavior. 105 | ++p_next_in; 106 | #endif 107 | break; // p_next_in points past the offending unit. 108 | } 109 | 110 | default: 111 | { 112 | assert(( "Should never get here.", false )); throw 0; 113 | break; 114 | } 115 | } 116 | } 117 | } 118 | }; 119 | 120 | }} // namespace stdlib::ext 121 | -------------------------------------------------------------------------------- /source/_impl/windows_console_io/Byte_console_input_buffer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | // Sillywarning that MSVC once didn't override when params differed by cv qualifiers! 6 | #ifdef _MSC_VER 7 | # pragma warning( disable: 4373 ) 8 | #endif 9 | 10 | #include // std::min 11 | #include // std::array 12 | #include // assert 13 | #include // ptrdiff_t 14 | #include 15 | #include // std::(begin, end) 16 | #include // std::basic_streambuf 17 | 18 | #include // Streaming_wide_to_byte_converter 19 | #include // general_buffer_size 20 | #include // apiwrap::* 21 | #include // and, or 22 | 23 | namespace stdlib{ namespace impl{ namespace windows_console_io{ 24 | using std::array; 25 | using std::basic_streambuf; 26 | using std::begin; 27 | using std::end; 28 | using std::min; 29 | using namespace stdlib::ext; 30 | 31 | class Utf8_line_input 32 | { 33 | static constexpr Size in_buffer_size = general_buffer_size; 34 | 35 | array_of_ in_buffer_; 36 | Size read_pos_ = 0; 37 | Size length_ = 0; 38 | Streaming_wide_to_byte_converter converter_; 39 | 40 | auto n_available_chars() const { return length_ - read_pos_; } 41 | 42 | auto read_from_buffer( const ptr_ out_buffer, const Size out_buffer_size ) 43 | -> Size 44 | { 45 | if( read_pos_ == length_ and converter_.n_buffered() == 0 ) 46 | { 47 | length_ = apiwrap::get_text_from_console( in_buffer_.data(), in_buffer_.size() ); 48 | read_pos_ = 0; 49 | if( length_ == 0 ) 50 | { 51 | return 0; 52 | } 53 | } 54 | 55 | const Size max_n_bytes = out_buffer_size; 56 | const Size max_n_wides = min( n_available_chars(), converter_.available_space() ); 57 | 58 | converter_.add( max_n_wides, in_buffer_.data() + read_pos_ ); 59 | read_pos_ += max_n_wides; 60 | return converter_.convert_into( out_buffer, max_n_bytes ); 61 | } 62 | 63 | public: 64 | auto read( const ptr_ out_buffer, const Size out_buffer_size ) 65 | -> Size 66 | { 67 | Size n_bytes_read = 0; 68 | for( ;; ) 69 | { 70 | const Size n_more_bytes = read_from_buffer( 71 | out_buffer + n_bytes_read, out_buffer_size - n_bytes_read 72 | ); 73 | n_bytes_read += n_more_bytes; 74 | if( n_more_bytes == 0 or 75 | n_bytes_read == out_buffer_size or 76 | out_buffer[n_bytes_read - 1] == '\n' ) 77 | { 78 | return n_bytes_read; 79 | } 80 | } 81 | } 82 | }; 83 | 84 | inline auto utf8_line_input() 85 | -> ref_ 86 | { 87 | static Utf8_line_input the_line_input; 88 | return the_line_input; 89 | } 90 | 91 | class Byte_console_input_buffer 92 | : public basic_streambuf 93 | { 94 | static constexpr Size buffer_size = general_buffer_size; 95 | using Base = basic_streambuf; 96 | using Traits = traits_type; 97 | 98 | char buffer_[buffer_size]; 99 | 100 | Byte_console_input_buffer( ref_ ) = delete; 101 | 102 | auto readbuf_start() const -> ptr_ { return Base::eback(); } 103 | auto readbuf_beyond() const -> ptr_ { return Base::egptr(); } 104 | 105 | auto read_position() const -> ptr_ { return Base::gptr(); } 106 | void advance_read_position( const int n ) { Base::gbump( n ); } 107 | 108 | protected: 109 | auto pbackfail( const int_type ch ) 110 | -> int_type 111 | override 112 | { (void) ch; return traits_type::eof(); } // TODO: 113 | 114 | auto underflow() // Called by uflow() 115 | -> int_type 116 | override 117 | { 118 | assert( read_position() == readbuf_beyond() ); 119 | 120 | const auto p_start = readbuf_start(); 121 | const Size n = utf8_line_input().read( p_start, buffer_size ); 122 | 123 | Base::setg( p_start, p_start, p_start + n ); 124 | return (n == 0? Traits::eof() : Traits::to_int_type( *read_position() )); 125 | } 126 | 127 | public: 128 | Byte_console_input_buffer() 129 | { Base::setg( buffer_, buffer_, buffer_ ); } 130 | }; 131 | }}} // namespace stdlib::impl::windows_console_io 132 | -------------------------------------------------------------------------------- /source/_impl/windows_console_io/Console_output_buffer_.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #include // assert 6 | #include // placement new 7 | #include // std::basic_streambuf 8 | 9 | #include // Streaming_byte_to_wide_converter 10 | #include // apiwrap::put_text_to_console 11 | 12 | namespace stdlib{ namespace impl{ namespace windows_console_io{ 13 | using std::basic_streambuf; 14 | using std::min; 15 | using std::streamsize; 16 | using std::wstring; 17 | 18 | inline auto write( const ptr_ data, const Size n ) 19 | -> Size 20 | { return apiwrap::put_text_to_console( data, n ); } 21 | 22 | inline auto write( const ptr_ data, const Size n ) 23 | -> Size 24 | { 25 | // Shenanigans to avoid (too early) destruction of the singleton converter: 26 | using Byte = unsigned char; 27 | alignas( Streaming_byte_to_wide_converter ) 28 | static raw_array_of_ converter_storage; 29 | static auto* const converter = ::new( &converter_storage ) Streaming_byte_to_wide_converter{}; 30 | 31 | constexpr Size result_size = Streaming_byte_to_wide_converter::in_buf_size; 32 | ptr_ p_source = data; 33 | wchar_t result[result_size]; 34 | Size n_consumed = 0; 35 | 36 | for( ;; ) 37 | { 38 | const Size n_remaining = n - n_consumed; 39 | const auto chunk_size = min( converter->available_space(), n_remaining ); 40 | converter->add( chunk_size, p_source ); 41 | const Size n_converted = converter->convert_into( result, result_size ); 42 | const Size n_written = write( result, n_converted ); 43 | if( n_written < n_converted ) 44 | { 45 | break; // But really, how to signal an i/o error after translate? 46 | } 47 | n_consumed += chunk_size; 48 | assert( n_consumed <= n ); 49 | if( n_consumed == n ) 50 | { 51 | break; 52 | } 53 | p_source += chunk_size; 54 | } 55 | return n_consumed; 56 | } 57 | 58 | template< class Char > struct Complement_of_; 59 | template<> struct Complement_of_ { using T = wchar_t; }; 60 | template<> struct Complement_of_ { using T = char; }; 61 | 62 | template< class Char > 63 | class Console_output_buffer_ 64 | : public basic_streambuf 65 | { 66 | static constexpr Size buffer_size = 8; 67 | using Base = basic_streambuf; 68 | using Traits = typename Base::traits_type; 69 | using typename Base::char_type; 70 | using typename Base::int_type; 71 | using Other_char = typename Complement_of_::T; 72 | using Other_buffer = Console_output_buffer_; 73 | 74 | friend Other_buffer; 75 | 76 | ptr_ p_buddy_ = nullptr; 77 | array_of_ buffer_; 78 | 79 | Console_output_buffer_( ref_ ) = delete; 80 | 81 | auto writebuf_start() const -> ptr_ { return Base::pbase(); } 82 | auto writebuf_beyond() const -> ptr_ { return Base::epptr(); } 83 | auto write_position() const -> ptr_ { return Base::pptr(); } 84 | 85 | void advance_write_position( const int n ) { Base::pbump( n ); } 86 | 87 | void flush_buddy_buffer() 88 | { 89 | if( p_buddy_ != nullptr ) 90 | { 91 | p_buddy_->flush(); 92 | } 93 | } 94 | 95 | protected: 96 | auto flush( const int n_extra = 0 ) 97 | -> bool 98 | { 99 | const auto p_start = writebuf_start(); 100 | const Size n = (write_position() - writebuf_start()) + n_extra; 101 | const Size n_written = write( p_start, n ); 102 | if( n_written != n ) 103 | { 104 | return false; 105 | } 106 | Base::setp( p_start, p_start + (buffer_size - 1) ); 107 | return true; 108 | } 109 | 110 | auto overflow( const int_type c ) 111 | -> int_type 112 | override 113 | { 114 | assert( write_position() <= writebuf_beyond() ); 115 | 116 | int n_extra = 0; 117 | if( not Traits::eq_int_type( c, Traits::eof() ) ) 118 | { 119 | flush_buddy_buffer(); 120 | *write_position() = static_cast( c ); 121 | ++n_extra; 122 | } 123 | const bool success = flush( n_extra ); 124 | return (success? Traits::not_eof( c ) : Traits::eof()); 125 | } 126 | 127 | auto sync() 128 | -> int 129 | override 130 | { return (flush()? 0 : -1); } // -1 = failure. 131 | 132 | auto xsputn( ptr_ s, const streamsize n ) 133 | -> streamsize 134 | override 135 | { 136 | flush_buddy_buffer(); 137 | return Base::xsputn( s, n ); 138 | } 139 | 140 | public: 141 | void set_buddy( const ptr_ p_other ) 142 | { 143 | assert( p_buddy_ == nullptr ); 144 | p_buddy_ = p_other; 145 | } 146 | 147 | ~Console_output_buffer_() 148 | override 149 | { flush(); } 150 | 151 | Console_output_buffer_() 152 | { 153 | const ptr_ buffer_start = buffer_.data(); 154 | const ptr_ buffer_beyond = buffer_start + (buffer_.size() - 1); 155 | Base::setp( buffer_start, buffer_beyond ); 156 | } 157 | }; 158 | 159 | using Byte_console_output_buffer = Console_output_buffer_; 160 | using Wide_console_output_buffer = Console_output_buffer_; 161 | 162 | }}} // namespace stdlib::impl::windows_console_io 163 | -------------------------------------------------------------------------------- /source/_impl/windows_console_io.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 4 | 5 | #ifndef _WIN32 6 | # error This file is only meaningful in Windows. 7 | #endif 8 | 9 | #include 10 | #include // size_t 11 | 12 | #include // ptr_ 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include // _isatty, _get_osfhandle (Visual C++ extensions supported by g++). 19 | 20 | // Output of a pure ASCII narrow string to a wide stream is safe. Output of a narrow 21 | // string with characters outside the ASCII range is likely to produce garbage, because 22 | // the machinery in Microsoft's runtime library interprets those bytes as Windows ANSI. 23 | // The following overload prevents inadvertent garbage result for attempted output of a 24 | // narrow literal to a wide stream, by making the call ambiguous. You can force such 25 | // output (resolving the ambiguity) by converting the literal to pointer, e.g. by 26 | // placing a `0+` in front of it: `wcout << 0+"Woo hoo, I'm using '+' instead of 'L'!";`. 27 | // But really, just use a wide literal, `L`. Unless it's a named narrow literal. 28 | // 29 | using STDLIB_MAKES_THIS_CALL_AMBIGUOUS_TO_PREVENT_GARBAGE_OUTPUT = char const; 30 | template< size_t n > 31 | auto operator<<( 32 | std::wostream&, 33 | STDLIB_MAKES_THIS_CALL_AMBIGUOUS_TO_PREVENT_GARBAGE_OUTPUT (&)[n] 34 | ) 35 | -> std::wostream&; 36 | 37 | namespace stdlib{ namespace impl{ namespace windows_console_io{ 38 | using std::cin; using std::cout; using std::cerr; using std::clog; 39 | using std::wcin; using std::wcout; using std::wcerr; using std::wclog; 40 | using std::basic_ios; 41 | using std::streambuf; 42 | using std::wstreambuf; 43 | 44 | class Envelope 45 | { 46 | private: 47 | static constexpr int n_std_streams = 4; 48 | const array_of_>> 49 | byte_streams_ = { &cin, &cout, &cerr, &clog }; 50 | const array_of_>> 51 | wide_streams_ = { &wcin, &wcout, &wcerr, &wclog }; 52 | 53 | array_of_> default_byte_buffer_ = {}; // Assigned by . 54 | array_of_> default_wide_buffer_ = {}; // Assigned by . 55 | 56 | winapi::DWord original_console_mode_ = winapi::DWord( -1 ); 57 | 58 | static auto is_console( const int stream_id ) 59 | -> bool 60 | { 61 | // return !!_isatty( stream_id ); //! False positive for redirection to nul device. :( 62 | auto const output_handle = reinterpret_cast( _get_osfhandle( stream_id ) ); 63 | winapi::DWord dummy; 64 | return !!winapi::GetConsoleMode( output_handle, &dummy ); 65 | } 66 | 67 | ~Envelope() 68 | { 69 | for( int i = 0; i < n_std_streams; ++i ) 70 | { 71 | if( default_byte_buffer_[i] != nullptr ) 72 | { 73 | byte_streams_[i]->rdbuf( default_byte_buffer_[i] ); 74 | } 75 | if( default_wide_buffer_[i] != nullptr ) 76 | { 77 | wide_streams_[i]->rdbuf( default_wide_buffer_[i] ); 78 | } 79 | } 80 | } 81 | 82 | Envelope() 83 | { 84 | static Byte_console_input_buffer byte_in_buf; 85 | static Byte_console_output_buffer byte_out_buf; 86 | static Byte_console_output_buffer byte_err_buf; 87 | static Byte_console_output_buffer byte_log_buf; 88 | 89 | static Wide_console_input_buffer wide_in_buf; 90 | static Wide_console_output_buffer wide_out_buf; 91 | static Wide_console_output_buffer wide_err_buf; 92 | static Wide_console_output_buffer wide_log_buf; 93 | 94 | byte_out_buf.set_buddy( &wide_out_buf ); 95 | wide_out_buf.set_buddy( &byte_out_buf ); 96 | 97 | byte_err_buf.set_buddy( &wide_err_buf ); 98 | wide_err_buf.set_buddy( &byte_err_buf ); 99 | 100 | byte_log_buf.set_buddy( &wide_log_buf ); // TODO: consider err streams too. 101 | wide_log_buf.set_buddy( &byte_log_buf ); 102 | 103 | const raw_array_> byte_buffers = 104 | { 105 | &byte_in_buf, &byte_out_buf, &byte_err_buf, &byte_log_buf 106 | }; 107 | 108 | const raw_array_> wide_buffers = 109 | { 110 | &wide_in_buf, &wide_out_buf, &wide_err_buf, &wide_log_buf 111 | }; 112 | 113 | for( int i = 0; i < n_std_streams; ++i ) 114 | { 115 | const int c_stream_id = (i > 2? 2 : i); 116 | if( is_console( c_stream_id ) ) 117 | { 118 | default_byte_buffer_[i] = byte_streams_[i]->rdbuf( byte_buffers[i] ); 119 | default_wide_buffer_[i] = wide_streams_[i]->rdbuf( wide_buffers[i] ); 120 | 121 | #ifndef STDLIB_NO_ANSI_ESCAPES_FIX 122 | if( i > 0 ) 123 | { 124 | // enable_ansi_escape_codes() doesn't work with a direct i/o 125 | // handle, must use a stream handle; possibly it's per stream. 126 | const auto h = reinterpret_cast( 127 | _get_osfhandle( c_stream_id ) 128 | ); 129 | winapi::DWord const old_mode = apiwrap::enable_ansi_escape_codes( h ); 130 | if( original_console_mode_ == winapi::DWord( -1 ) ) 131 | { 132 | original_console_mode_ = old_mode; 133 | } 134 | } 135 | #endif 136 | } 137 | } 138 | } 139 | 140 | public: 141 | static auto make_singleton() 142 | -> bool 143 | { 144 | static Envelope the_envelope; 145 | return true; 146 | } 147 | }; 148 | 149 | const bool dummy = Envelope::make_singleton(); 150 | 151 | }}} // namespace stdlib::impl::windows_console_io 152 | -------------------------------------------------------------------------------- /source/_impl/windows_char_path.hpp: -------------------------------------------------------------------------------- 1 | #pragma once // Source encoding: utf-8 with BOM ∩ 2 | // #include 3 | // 4 | // Best effort compatible-with-runtime-library path. 5 | // In Windows some result path items can be alternate short names, if that’s 6 | // available for the file system, unless the long path is all ASCII, in which 7 | // case it’s just returned as-is. 8 | // 9 | // Copyright © 2017 Alf P. Steinbach, distributed under Boost license 1.0. 10 | 11 | #ifndef _WIN32 12 | # error This file is only meaningful in Windows. 13 | #endif 14 | 15 | #include 16 | 17 | #include 18 | 19 | #include // stdlib::impl:winapi::* 20 | #include // stdlib::ext::ascii::contains_all 21 | #include // stdlib::ext::(hopefully, fail) 22 | #include // stdlib::ext::(ref_) 23 | #include // stdlib::ext::(utf8_from, wide_from_utf8) 24 | 25 | namespace stdlib{ namespace ext{ 26 | using std::string; 27 | using std::wstring; 28 | using namespace std::literals; 29 | 30 | namespace impl { 31 | using namespace ext; 32 | 33 | inline auto is_pseudo_path_item( ptr_ name ) 34 | -> bool 35 | { 36 | if( wcscmp( name, L"." ) == 0 or wcscmp( name, L".." ) == 0 ) 37 | { 38 | return true; 39 | } 40 | if( wcspbrk( name, L"*?:" ) != nullptr ) 41 | { 42 | return true; 43 | } 44 | return false; 45 | } 46 | 47 | //inline auto is_pseudo_path_item( ref_ name ) 48 | // -> bool 49 | //{ 50 | // if( name == L"." or name == L".." ) 51 | // { 52 | // return true; 53 | // } 54 | // if( name.find_first_of( L"*?:" ) != wstring::npos ) 55 | // { 56 | // return true; 57 | // } 58 | // return false; 59 | //} 60 | 61 | struct Possibly_empty_string 62 | { 63 | string value; 64 | explicit operator bool() const { return (value.length() > 0); } 65 | }; 66 | 67 | inline auto ansi_from( 68 | const ptr_ item, 69 | const Size item_len, 70 | const bool substitution_allowed = false 71 | ) 72 | noexcept 73 | -> Possibly_empty_string 74 | { 75 | namespace w = stdlib::impl::winapi; 76 | assert( item_len > 0 ); 77 | 78 | string result( item_len, '\0' ); 79 | w::Bool used_substitution = false; 80 | Size const n_bytes = static_cast( w::WideCharToMultiByte( 81 | w::cp_acp, // CodePage 82 | w::wc_no_best_fit_chars, // dwFlags 83 | item, // lpWideCharStr 84 | static_cast( item_len ), // cchWideChar, 85 | &result[0], // lpMultiByteStr 86 | static_cast( result.size() ), // cbMultiByte 87 | &ascii::bad_char, // lpDefaultChar 88 | &used_substitution // lpUsedDefaultChar 89 | ) ); 90 | 91 | if( n_bytes == 0 or used_substitution and not substitution_allowed ) 92 | { 93 | return {}; 94 | } 95 | 96 | result.resize( n_bytes ); 97 | return { move( result ) }; 98 | } 99 | 100 | struct Possibly_empty_wstring 101 | { 102 | wstring value; 103 | explicit operator bool() const { return (value.length() > 0); } 104 | }; 105 | 106 | inline auto alternate_name( 107 | const ptr_ path, 108 | const ptr_ last_item 109 | ) 110 | noexcept 111 | -> Possibly_empty_wstring 112 | { 113 | if( is_pseudo_path_item( last_item ) ) 114 | { 115 | return {}; 116 | } 117 | namespace w = stdlib::impl::winapi; 118 | w::Win32_find_data info{}; 119 | w::Handle const h = w::FindFirstFileW( path, &info ); 120 | w::FindClose( h ); 121 | const ptr_ ws = info.cAlternateFileName; 122 | bool const ok = (h != w::Handle( -1 ) and ws[0] != L'\0'); 123 | return {ok? ws : L""}; 124 | } 125 | 126 | inline auto ansi_path( 127 | wstring long_path, 128 | const bool substitution_allowed = false 129 | ) 130 | -> wstring 131 | { 132 | if( long_path.length() == 0 ) { return long_path; } 133 | long_path.append( L"\0\0", 2 ); 134 | 135 | wstring result; 136 | replace( long_path.begin(), long_path.end(), '\\', '\0' ); 137 | 138 | for( ptr_ p = &long_path[0]; *p != L'\0'; p += wcslen( p ) + 1 ) 139 | { 140 | if( result.length() > 0 ) 141 | { 142 | result += L'\\'; 143 | *(p - 1) = L'\\'; 144 | } 145 | 146 | Size const n = wcslen( p ); 147 | if( ascii::contains_all( p, p + n ) ) 148 | { 149 | result += p; 150 | } 151 | else if( const auto ansi = ansi_from( p, n, false ) ) 152 | { 153 | result.append( ansi.value.begin(), ansi.value.end() ); 154 | } 155 | else if( const auto alt = alternate_name( &long_path[0], p )) 156 | { 157 | result += alt.value; 158 | } 159 | else if( substitution_allowed ) 160 | { 161 | const auto rough_ansi = ansi_from( p, n, true ); 162 | assert( rough_ansi.value.length() > 0 ); 163 | result.append( rough_ansi.value.begin(), rough_ansi.value.end() ); 164 | } 165 | else 166 | { 167 | fail( string() 168 | + "stdlib::impl::ansi_path - unable to represent last item in" 169 | + " “" + utf8_from( &long_path[0] ) + "”" 170 | ); 171 | } 172 | } 173 | return result; 174 | } 175 | } // namespace impl 176 | 177 | inline auto char_path_with_substitution( const bool substitution_allowed, wstring long_path ) 178 | -> string 179 | { 180 | if( ascii::contains_all( long_path.begin(), long_path.end() ) ) 181 | { 182 | return string( long_path.begin(), long_path.end() ); 183 | } 184 | wstring const ws = impl::ansi_path( long_path, substitution_allowed ); 185 | return string( ws.begin(), ws.end() ); 186 | } 187 | 188 | inline auto char_path_with_substitution( const bool substitution_allowed, string long_utf8_path ) 189 | -> string 190 | { 191 | if( ascii::contains_all( long_utf8_path.begin(), long_utf8_path.end() ) ) 192 | { 193 | return long_utf8_path; 194 | } 195 | wstring const ws = impl::ansi_path( wide_from_utf8( long_utf8_path ), substitution_allowed ); 196 | return string( ws.begin(), ws.end() ); 197 | } 198 | 199 | }} // namespace stdlib::ext 200 | 201 | -------------------------------------------------------------------------------- /images/icon/wrapped-stdlib-icon - 1.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 28 | 33 | 39 | 44 | 49 | 55 | 56 | 60 | 65 | 71 | 76 | 81 | 87 | 88 | 92 | 97 | 103 | 108 | 113 | 119 | 120 | 124 | 129 | 135 | 140 | 145 | 151 | 152 | 156 | 161 | 167 | 172 | 177 | 183 | 184 | 188 | 193 | 199 | 204 | 209 | 215 | 216 | 217 | 239 | 241 | 242 | 244 | image/svg+xml 245 | 247 | 248 | 249 | 250 | 251 | 256 | 260 | Wrappedstdlib 275 | 276 | 277 | 278 | -------------------------------------------------------------------------------- /images/icon/wrapped-stdlib-icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 28 | 33 | 39 | 44 | 49 | 55 | 56 | 60 | 65 | 71 | 76 | 81 | 87 | 88 | 92 | 97 | 103 | 108 | 113 | 119 | 120 | 124 | 129 | 135 | 140 | 145 | 151 | 152 | 156 | 161 | 167 | 172 | 177 | 183 | 184 | 188 | 193 | 199 | 204 | 209 | 215 | 216 | 217 | 239 | 241 | 242 | 244 | image/svg+xml 245 | 247 | 248 | 249 | 250 | 251 | 256 | 260 | Wrappedstdlib 275 | 276 | 277 | 278 | --------------------------------------------------------------------------------