diff --git a/docs/docs/01.helloworld/index.html b/docs/docs/01.helloworld/index.html new file mode 100644 index 000000000..d08d20264 --- /dev/null +++ b/docs/docs/01.helloworld/index.html @@ -0,0 +1,49 @@ + + + + + + Hello World - fast_io Documentation + + + + +
+

Hello World

+ +
+

Hello World

+

+ A minimal program using fast_io to print Hello World: +

+

+#include <fast_io.h>
+
+int main()
+{
+    using namespace ::fast_io::io;
+    print("Hello World\n");
+}
+
+

+ By default, ::fast_io::io::print writes to C’s FILE* stdout object. + This means the output goes to the standard output stream, just like printf or + std::cout, but with safer and faster semantics. +

+

+ In practice, using fast_io together with stdio or iostream + usually does not cause issues. The only problematic cases arise if code calls unusual functions + like unput, which can break assumptions because neither stdio nor + iostream guarantee consistent behavior for such operations. As long as you avoid + those unsafe edge cases, interoperability is fine. +

+
+ + +
+ + diff --git a/docs/docs/02.aplusb/index.html b/docs/docs/02.aplusb/index.html new file mode 100644 index 000000000..3d0992a4a --- /dev/null +++ b/docs/docs/02.aplusb/index.html @@ -0,0 +1,124 @@ + + + + + + A + B - fast_io Documentation + + + + +
+

A + B

+ +
+

Basic Input and Output

+

+ A simple program that reads two integers and prints their sum. This demonstrates + scan for input and println for output: +

+

+#include <fast_io.h>
+
+using namespace fast_io::io;
+
+int main()
+{
+    std::size_t a, b;
+    scan(a, b);
+    println(a + b);
+}
+
+
+ +
+

What is a Manipulator?

+

+ In fast_io, a manipulator is a helper object that changes how + input or output is interpreted or formatted. Instead of relying on unsafe format strings, + manipulators make the intent explicit in the type system. +

+

+ Manipulators are defined in the namespace fast_io::manipulators, which is aliased + as fast_io::mnp for convenience. They make input and output safer, more explicit, + and more portable than traditional stdio or iostream. +

+

+ For example: +

+ +
+ +
+

Hexadecimal Manipulators

+

+ fast_io provides manipulators to read and print numbers in hexadecimal. + hex_get reads input in hex, while hex and hexupper + print output in lowercase or uppercase hex respectively: +

+

+#include <fast_io.h>
+
+using namespace fast_io::io;
+
+int main()
+{
+    using namespace fast_io::mnp;
+    std::size_t a, b;
+    scan(hex_get(a), hex_get(b));
+    println(hex(a + b), " ", hexupper(a + b));
+}
+
+
+ +
+

Base-N Manipulators

+

+ Manipulators also support arbitrary bases from 2 to 36. Here’s an example using base 36: +

+

+#include <fast_io.h>
+
+using namespace fast_io::io;
+
+int main()
+{
+    using namespace fast_io::mnp;
+    std::size_t a, b;
+    scan(base_get<36>(a), base_get<36>(b));
+    println(base<36>(a + b));
+}
+
+
+ +
+

About Manipulators

+

+ fast_io defines a rich set of manipulators to control input and output formatting. + For convenience, the namespace fast_io::manipulators is aliased as fast_io::mnp. +

+ +

+ These manipulators make it easy to work with different numeric bases without relying on unsafe format strings. +

+
+ + +
+ + diff --git a/docs/docs/03.pointer/index.html b/docs/docs/03.pointer/index.html new file mode 100644 index 000000000..b1d5bc9a9 --- /dev/null +++ b/docs/docs/03.pointer/index.html @@ -0,0 +1,163 @@ + + + + + + Pointers - fast_io Documentation + + + + +
+

Pointers

+ +
+

Introduction

+

+ In fast_io, raw pointers and iterators are not printed directly. This is a deliberate + safety choice: printing them without explicit intent can lead to undefined or inconsistent + behavior across platforms. Instead, fast_io provides a family of pointer‑related + manipulators that make the intent explicit and ensure consistent, portable formatting. +

+
+ +
+

Pointer Manipulators Overview

+ +
+ +
+

Printing Pointers

+

+ Use pointervw to print raw addresses. The format is consistent across platforms: + 0x followed by 8 hex digits on 32‑bit systems, or 16 hex digits on 64‑bit systems. +

+

+#include <fast_io.h>
+
+using namespace fast_io::io;
+
+int main()
+{
+    using namespace fast_io::mnp;
+    int x{42};
+    int *ptr{::std::addressof(x)};
+    println("Address:", pointervw(ptr));
+}
+      
+
+ +
+

C‑String Manipulator

+

+ To treat a char const* as a C‑string, use os_c_str. This calls + strlen or strnlen depending on overload. +

+

+#include <fast_io.h>
+
+int main()
+{
+    using namespace fast_io::io;
+    using namespace fast_io::mnp;
+    constexpr char const* ptr{"Hello\0World\n"};
+
+    println(
+        "Literal: Hello\0World\n\n"
+        "Pointer:", pointervw(ptr), "\n"
+        "os_c_str:", os_c_str(ptr), "\n"
+        "os_c_str(ptr,4):", os_c_str(ptr,4), "\n"
+        "os_c_str(ptr,10):", os_c_str(ptr,10)
+    );
+}
+      
+
+ +
+

Function and Method Pointers

+

+ funcvw prints the address of a free function. methodvw prints member + function pointers, including offset information for multiple inheritance cases. +

+

+#include <fast_io.h>
+#include <memory>
+
+class dummy_class { public: void dummy_method() noexcept {} };
+struct A { virtual void f() noexcept {} };
+struct B { virtual void g() noexcept {} };
+struct C : A, B {};
+
+using namespace fast_io::io;
+
+void foo(){}
+
+int main()
+{
+    using namespace fast_io::mnp;
+    void (C::*downcptr)() noexcept = &B::g;
+
+    println(
+        "funcvw(foo):", funcvw(foo), "\n"
+
+        "methodvw(&dummy_class::dummy_method):",
+        methodvw(&dummy_class::dummy_method), "\n"
+
+        "methodvw(downcptr):", methodvw(downcptr)
+    );
+}
+      
+
+ +
+

Handles

+

+ handlevw is used when printing operating system handles. A handle may be an + integer (POSIX file descriptor) or a pointer (Win32 HANDLE, FILE*). + handlevw adapts automatically, printing integers directly and pointers in + consistent hexadecimal format. +

+

+#include <fast_io.h>
+#include <cstdio>
+
+using namespace fast_io::io;
+
+int main()
+{
+    using namespace fast_io::mnp;
+    int fd{3};       // POSIX file descriptor
+    FILE *f{stdout};
+
+    println(
+        "POSIX fd:", handlevw(fd), "\n"
+        "FILE* handle:", handlevw(f)
+    );
+}
+      
+
+ +
+

Summary

+

+ Pointer‑related manipulators in fast_io make printing low‑level entities explicit, + safe, and portable. They cover raw pointers, C‑strings, free functions, member functions, + and OS handles. This design avoids the unsafe and inconsistent behavior of + stdio and iostream. +

+
+ + +
+ + diff --git a/docs/docs/04.fileio/index.html b/docs/docs/04.fileio/index.html new file mode 100644 index 000000000..e68c4d5d5 --- /dev/null +++ b/docs/docs/04.fileio/index.html @@ -0,0 +1,104 @@ + + + + + + File I/O - fast_io Documentation + + + + +
+

File I/O

+ +
+

Basic File Input and Output

+

+ fast_io provides file types such as ibuf_file and obuf_file + for buffered input and output. File names can be passed as any character type, and the + os_c_str manipulator applies here as well. +

+

+#include <fast_io.h>
+#include <fast_io_device.h>
+
+int main()
+{
+    ::fast_io::ibuf_file ibf(u8"aplusb_in.txt");
+    ::fast_io::obuf_file obf(u8"aplusb_out.txt");
+    ::std::size_t a, b;
+    scan(ibf, a, b);
+    println(obf, a + b);
+}
+      
+
+ +
+

Directory Files

+

+ dir_file represents a directory handle. You can open files relative to a directory + using at(dir). This makes it easy to work with subdirectories and ensures + portability across platforms. +

+

+#include <fast_io.h>
+#include <fast_io_device.h>
+
+int main(int argc, char** argv)
+{
+    ::fast_io::dir_file dir(fast_io::mnp::os_c_str(argv[1]));
+    ::fast_io::obuf_file obf(at(dir), u8"hello.txt");
+    println(obf, "Hello World\n");
+
+    ::fast_io::dir_file subdir(at(dir), u8"subdir");
+    ::fast_io::u8obuf_file u8obf(at(subdir), u8"hellou8.txt");
+    println(u8obf, u8"Hello World for subdir\n");
+}
+      
+
+ +
+

Native File Loader

+

+ native_file_loader uses the operating system’s memory mapping API (if available) + to load an entire file into memory. The file is exposed as a contiguous container, allowing + iteration and direct access. +

+

+#include <fast_io.h>
+
+using namespace fast_io::io;
+
+int main(int argc, char **argv)
+{
+    if (argc != 2)
+    {
+        if (argc == 0)
+        {
+            return 1;
+        }
+        perr("Usage: ", fast_io::mnp::os_c_str(*argv), " <file>\n");
+        return 1;
+    }
+    fast_io::native_file_loader loader(::fast_io::mnp::os_c_str(argv[1]));
+    // This will load the entire file into memory through memory mapping.
+    /*
+    This is a contiguous container of the file.
+    You can do things like:
+    std::size_t sum{};
+    for(auto e : loader)
+        sum += e;
+    */
+    print(loader);
+}
+      
+
+ + +
+ + diff --git a/docs/docs/05.filetypelayers/index.html b/docs/docs/05.filetypelayers/index.html new file mode 100644 index 000000000..5a9e80f06 --- /dev/null +++ b/docs/docs/05.filetypelayers/index.html @@ -0,0 +1,215 @@ + + + + + + File Type Layers - fast_io Documentation + + + + +
+

File Type Layers

+ +
+

Overview

+

+ fast_io organizes its file types into six layers. Each layer corresponds to a + different level of abstraction, from direct operating system calls up to C and C++ runtime + facilities. On top of these file types, fast_io provides operations + that unify input and output for all of them through Concepts. +

+
+ +
+

Hierarchy of File Types

+

From bottom to top:

+
    +
  1. wine
  2. +
  3. nt
  4. +
  5. win32
  6. +
  7. posix
  8. +
  9. c
  10. +
  11. filebuf
  12. +
+
+ +
+

Explainations for the Hierarchy of File Types

+

From bottom to top:

+
    +
  1. + wine — + ::fast_io::wine_file is the lowest layer used when running Windows binaries on POSIX systems (e.g. Linux, FreeBSD) via Wine. It directly interacts with Wine’s emulated NT kernel APIs. +
  2. +
  3. + nt — + ::fast_io::nt_file accesses the Windows NT kernel directly via NtWriteFile and related syscalls. This is the most native and lowest-level file interface on modern Windows systems (NT, 2000, XP, 7, 10, etc). +
  4. +
  5. + win32 — + ::fast_io::win32_file wraps the Win32 API’s WriteFile function via kernel32.dll. It is higher-level than NT and used for compatibility with user-mode Windows applications. +
  6. +
  7. + posix — + ::fast_io::posix_file wraps POSIX-style file descriptors and maps to write(2) on Unix-like systems. On Windows, it is emulated via MSVCRT or UCRT. +
  8. +
  9. + c — + ::fast_io::c_file exposes the C standard library’s FILE* interface (e.g. fwrite(3)). It provides buffering and is widely used in legacy C code. +
  10. +
  11. + filebuf — + ::fast_io::filebuf_file exposes the C++ standard library’s std::filebuf* interface, used by std::fstream. It is the highest-level abstraction and integrates with C++ I/O streams. +
  12. +
+
+ +
+

Unbuffered Layers

+

+ The first four layers are unbuffered. They map directly to OS APIs and do not + add buffering: +

+ +

+ Each of these also has character type variants, for example: +

+ +

+ These variants allow working with UTF‑8, UTF‑32, or wide character filenames depending + on platform conventions. +

+
+ +
+

Buffered Layers

+

+ The top two layers expose existing buffered facilities provided by the C and C++ runtime + libraries: +

+ +

+ Note: filebuf_file only has ::fast_io::filebuf_file and + ::fast_io::wfilebuf_file. Why? Because the C++ standard library never + implemented basic functionality for other character types such as + ::fast_io::u8filebuf_file. Only narrow and wide character streams are + supported. +

+
+ +
+

Moving Between Layers

+

+ You can construct higher‑level types from lower ones (through std::move), or go + back down (through static_cast). +

+

+// Lower to higher
+::fast_io::nt_file nfl("nt.txt", ::fast_io::open_mode::out);
+print(nfl, "Hello World from nt_file\n");
+
+::fast_io::filebuf_file fbf(std::move(nfl), ::fast_io::open_mode::out);
+print(fbf, "Hello World from filebuf_file\n");
+
+// Higher to lower
+::fast_io::filebuf_file fbf2("fb.txt", ::fast_io::open_mode::out);
+::fast_io::nt_io_observer niob{static_cast<::fast_io::nt_io_observer>(fbf2)};
+print(niob, "Hello World from nt_io_observer\n");
+      
+
+ +
+

Observers

+

+ Types like xxx_io_observer are simple aggregates that store a handle. They are + trivially copyable, have no destructors, and let you safely pass handles around without + ownership semantics. +

+

+void foo(FILE* fp) {
+    ::fast_io::c_io_observer ciob{fp};
+    print(ciob, "Hello World from c_io_observer\n");
+
+    ::fast_io::nt_io_observer niob{static_cast<::fast_io::nt_io_observer>(ciob)};
+    print(niob, "Hello World from nt_io_observer\n");
+
+    // Inspect native handle
+    print(::fast_io::mnp::handlevw(niob.native_handle()));
+}
+      
+
+ +
+

Native File and iobuf_file

+

+ ::fast_io::native_file is an alias to the most appropriate unbuffered file type for + the platform: +

+ +

+ basic_iobuf_file is defined as: +

+

+template<std::integral char_type>
+using basic_iobuf_file = basic_iobuf<basic_native_file<char_type>>;
+      
+

+ This means iobuf_file is a buffered stream built directly on top of the native file + type for your system. +

+
+ +
+

Interop with fstream

+

+ You can construct a C++ fstream from system calls using fast_io. Here’s + a simplified example without the middle c_file layer: +

+

+#include <fast_io_legacy.h>
+#include <fstream>
+
+int main() {
+    ::fast_io::posix_file pf("posix_file.txt", ::fast_io::open_mode::out);
+    ::fast_io::filebuf_file fbf(std::move(pf), ::fast_io::open_mode::out);
+
+    std::ofstream fout;
+    *fout.rdbuf() = std::move(*fbf.fb);
+
+    fout << "Hello World from std::ofstream\n";
+
+    ::fast_io::filebuf_io_observer fiob{fout.rdbuf()};
+    print(fiob, "Hello World from fast_io::filebuf_io_observer\n");
+}
+      
+

+ If you don’t need fstream, using std::ostream directly with + *rdbuf() is even simpler and avoids the overhead of fstream. +

+
+ + +
+ + diff --git a/docs/docs/api.html b/docs/docs/api/index.html similarity index 100% rename from docs/docs/api.html rename to docs/docs/api/index.html diff --git a/docs/docs/examples.html b/docs/docs/examples.html deleted file mode 100644 index d3e0d864b..000000000 --- a/docs/docs/examples.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - Examples - fast_io Documentation - - - - -
-

Examples

- -
-

Hello World Example

-

- A minimal program using fast_io to print Hello World: -

-

-#include <fast_io.h>
-
-int main()
-{
-    using namespace ::fast_io::io;
-    print("Hello World\n");
-}
-
-
- - -
-

More Examples Coming Soon

-

- Additional examples demonstrating input, file handling, and platform compatibility will be added here. -

-
- - -
- - - diff --git a/docs/docs/intro.html b/docs/docs/intro/index.html similarity index 95% rename from docs/docs/intro.html rename to docs/docs/intro/index.html index 4f6ab8ad8..9fa1cc15e 100644 --- a/docs/docs/intro.html +++ b/docs/docs/intro/index.html @@ -148,8 +148,9 @@

Video Introduction

-
- Next: Examples → + diff --git a/docs/footer.html b/docs/footer.html deleted file mode 100644 index 176582e06..000000000 --- a/docs/footer.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 71e966117..5ca2fa1ef 100644 --- a/docs/index.html +++ b/docs/index.html @@ -4,15 +4,19 @@ fast_io - fast_io documentations (Under Construction) - - + +

fast_io