Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/X-ARTEMIS/ASTD/llms.txt

Use this file to discover all available pages before exploring further.

This quickstart walks you through a single, self-contained program that exercises every ASTD module — math, fraction, and time — so you can see real function signatures, construction patterns, and expected output before diving into the individual API references. If you have not yet copied the astd/ directory into your project, complete the Installation guide first.
1

Include the umbrella header

One #include is all you need to bring every ASTD module into scope. Add it at the top of your source file alongside the standard headers your program uses directly.
#include "astd/astd.hpp"
#include <cassert>
#include <iostream>
astd.hpp transitively includes:
  • astd/math/math.hpp → re-exports cppmath.hpp (free math functions) and fraction.hpp (the fraction<T,U> class)
  • astd/time/time.hpp → the astd::getSystemTime and astd::getSystemTrimmedTime functions
If you only need one module you can include its header directly (e.g., #include "astd/math/math.hpp"), which reduces preprocessor work in large projects.
2

Use the math functions

The math module provides three free functions, all defined with abbreviated function templates so they accept any numeric type without explicit instantiation.
int main() {
    // power(base, exponent) — iterative exponentiation
    // Returns 1 when exponent <= 0
    assert(power(2, 3) == 8); // verified by tests/math.cpp
    std::cout << "2^10    = " << power(2, 10)   << "\n"; // 1024
    std::cout << "3^0     = " << power(3, 0)    << "\n"; // 1
    std::cout << "5^3     = " << power(5, 3)    << "\n"; // 125

    // square(base) — shorthand for base * base
    std::cout << "sq(7)   = " << square(7)      << "\n"; // 49
    std::cout << "sq(1.5) = " << square(1.5)    << "\n"; // 2.25

    // getNumType(num) — true = even, false = odd
    std::cout << "4 even? " << std::boolalpha << getNumType(4) << "\n"; // true
    std::cout << "7 even? " << std::boolalpha << getNumType(7) << "\n"; // false
}
Expected output
2^10    = 1024
3^0     = 1
5^3     = 125
sq(7)   = 49
sq(1.5) = 2.25
4 even? true
7 even? false
power() returns an int literal 1 for non-positive exponents regardless of the base type. Keep this in mind if you need floating-point results for edge cases.
3

Work with fractions

fraction<T, U> is a class template where T is the numerator type and U is the denominator type. Construct it with a numerator and denominator value. Passing 0 as the denominator throws std::exception("Undefined fraction").
    // Construction: fraction<NumeratorType, DenominatorType>(numerator, denominator)
    fraction<int, int> a{1, 3};   // 1/3
    fraction<int, int> b{1, 6};   // 1/6

    // operator<< prints in "numerator/denominator" form
    std::cout << "a       = " << a << "\n"; // 1/3
    std::cout << "b       = " << b << "\n"; // 1/6

    // Compound addition: finds the LCM when denominators differ
    a += b;
    std::cout << "a + b   = " << a << "\n"; // 3/6  (1/3 + 1/6 = 2/6 + 1/6)

    // fractionToDecimal() converts to double
    fraction<int, int> half{1, 2};
    std::cout << "1/2 dec = " << half.fractionToDecimal() << "\n"; // 0.5

    fraction<int, int> third{1, 3};
    std::cout << "1/3 dec = " << third.fractionToDecimal() << "\n"; // 0.333333

    // Subtraction
    fraction<int, int> x{3, 4};
    fraction<int, int> y{1, 4};
    x -= y;
    std::cout << "3/4-1/4 = " << x << "\n"; // 2/4

    // Multiplication (same denominator path)
    fraction<int, int> p{2, 5};
    fraction<int, int> q{3, 5};
    p *= q;
    std::cout << "2/5*3/5 = " << p << "\n"; // 6/5

    // Undefined fraction guard
    try {
        fraction<int, int> bad{1, 0};
    } catch (const std::exception& e) {
        std::cout << "Error:  " << e.what() << "\n"; // Undefined fraction
    }
Expected output
a       = 1/3
b       = 1/6
a + b   = 3/6
1/2 dec = 0.5
1/3 dec = 0.333333
3/4-1/4 = 2/4
2/5*3/5 = 6/5
Error:  Undefined fraction
The compound operators (+=, -=, *=) modify the left-hand fraction in place and do not simplify the result to lowest terms. For example, 1/3 + 1/6 produces 3/6 rather than 1/2. Reduction is left to the caller.
4

Retrieve the system time

Both time functions live in the astd namespace and wrap std::chrono. Each accepts an optional bool local parameter that defaults to false (UTC). Pass true to get the local time zone instead.
    // getSystemTime() — full-precision system_clock time point (UTC)
    auto utcNow = astd::getSystemTime();
    std::cout << "UTC now:       " << utcNow << "\n";

    // getSystemTime(true) — local time zone
    auto localNow = astd::getSystemTime(true);
    std::cout << "Local now:     " << localNow << "\n";

    // getSystemTrimmedTime() — truncated to whole seconds (UTC)
    auto utcTrimmed = astd::getSystemTrimmedTime();
    std::cout << "UTC trimmed:   " << utcTrimmed << "\n";

    // getSystemTrimmedTime(true) — truncated to whole seconds, local zone
    auto localTrimmed = astd::getSystemTrimmedTime(true);
    std::cout << "Local trimmed: " << localTrimmed << "\n";
Example output (values will reflect the time of execution)
UTC now:       2024-06-15 13:42:07.348291200
Local now:     2024-06-15 09:42:07.348291200
UTC trimmed:   2024-06-15 13:42:07
Local trimmed: 2024-06-15 09:42:07
getSystemTrimmedTime() uses std::chrono::time_point_cast<std::chrono::seconds> to strip sub-second precision. Use it when you need human-readable timestamps without microsecond noise, such as for log entries or user-facing display strings.
5

Compile and run the complete program

Here is the full program from the steps above, ready to copy and compile:
#include "astd/astd.hpp"
#include <cassert>
#include <iostream>

int main() {
    // ── Math ──────────────────────────────────────────────────────────
    std::cout << "=== Math ===\n";
    assert(power(2, 3) == 8); // verified by tests/math.cpp
    std::cout << "2^10    = " << power(2, 10)   << "\n";
    std::cout << "3^0     = " << power(3, 0)    << "\n";
    std::cout << "5^3     = " << power(5, 3)    << "\n";
    std::cout << "sq(7)   = " << square(7)      << "\n";
    std::cout << "sq(1.5) = " << square(1.5)    << "\n";
    std::cout << "4 even? " << std::boolalpha << getNumType(4) << "\n";
    std::cout << "7 even? " << std::boolalpha << getNumType(7) << "\n";

    // ── Fraction ──────────────────────────────────────────────────────
    std::cout << "\n=== Fraction ===\n";
    fraction<int, int> a{1, 3};
    fraction<int, int> b{1, 6};
    std::cout << "a       = " << a << "\n";
    std::cout << "b       = " << b << "\n";
    a += b;
    std::cout << "a + b   = " << a << "\n";
    std::cout << "1/2 dec = " << fraction<int, int>{1, 2}.fractionToDecimal() << "\n";
    std::cout << "1/3 dec = " << fraction<int, int>{1, 3}.fractionToDecimal() << "\n";

    fraction<int, int> x{3, 4}, y{1, 4};
    x -= y;
    std::cout << "3/4-1/4 = " << x << "\n";

    fraction<int, int> p{2, 5}, q{3, 5};
    p *= q;
    std::cout << "2/5*3/5 = " << p << "\n";

    try {
        fraction<int, int> bad{1, 0};
    } catch (const std::exception& e) {
        std::cout << "Error:  " << e.what() << "\n";
    }

    // ── Time ──────────────────────────────────────────────────────────
    std::cout << "\n=== Time ===\n";
    std::cout << "UTC now:       " << astd::getSystemTime()            << "\n";
    std::cout << "Local now:     " << astd::getSystemTime(true)        << "\n";
    std::cout << "UTC trimmed:   " << astd::getSystemTrimmedTime()     << "\n";
    std::cout << "Local trimmed: " << astd::getSystemTrimmedTime(true) << "\n";

    return 0;
}
Compile with your toolchain’s C++20 flag:
g++ -std=c++20 -I. main.cpp -o main && ./main

Next steps

Math API Reference

Full reference for power(), square(), getNumType(), and every member of the fraction<T,U> class template.

Installation

Missed a step? Revisit the full installation guide covering GitHub Releases, git clone, and compiler flags.

Build docs developers (and LLMs) love