Zkouška 26. 5. 2026

Compile-time Query System

Implement a small type-safe compile-time query system inspired by SQL.

The goal is to support syntax like:

using Users = table<
    column<"id", int>,
    column<"name", std::string>,
    column<"age", int>
>;

using Q =
    query<Users>
    ::select<"name", "age">
    ::where<greater<"age", 18>>;

and obtain:

  • compile-time validation of column existence and its name uniqueness,

  • a compile-time representation of the resulting schema,

  • type-safe access to columns.

Requirements

  1. Table representation

Implement:

template<fixed_string Name, typename T>
struct column;

template<typename... Columns>
struct table;

Example:

using Users = table<
    column<"id", int>,
    column<"name", std::string>,
    column<"age", int>
>;
  1. Compile-time column lookup

Implement the metafunction:

column_type_t<Table, "name">

which returns the column type.

Example:

static_assert(std::same_as<column_type_t<Users, "age">, int>);

If the column does not exist, the program must fail at compile time.

If there are multiple columns with the same name, the program must also fail at compile time.

  1. SELECT

Implement:

query<Table>::select<Cols...>

which produces a new schema containing only the selected columns.

Example:

using Result =
    query<Users>::select<"name", "age">;

This must be equivalent to:

table<
    column<"name", std::string>,
    column<"age", int>
>;
  1. WHERE conditions Implement simple compile-time conditions:

greater<"age", 18>
equals<"name", "Alice">

The conditions do not need to filter runtime data. It is sufficient to:

  • carry a compile-time representation of the expression,

  • verify that the column exists,

  • verify type compatibility.

Example:

using Q = query<Users>::where<greater<"age", 18>>;

should compile successfully.

However:

using Q = query<Users>::where<greater<"name", 18>>;

must fail at compile time.

  1. Concepts Use concepts / requires clauses for:

  • validating conditions,

  • validating column existence and uniqueness,

  • checking type compatibility.

  1. fixed_string

Implement support for:

template<size_t N>
struct fixed_string;

so that it can be used as follows:

column<"age", int>

as a non-type template parameter.

Constraints You must not use:

  • external libraries,

  • runtime maps or string lookup.

Everything must work purely using templates, constexpr, and type transformations.

Submission

Submit ctsql.hpp into Recodex.

Tests named XXX-SHOULD_FAIL should fail