# 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:
```cpp
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:
```cpp
template<fixed_string Name, typename T>
struct column;

template<typename... Columns>
struct table;
```
**Example:**
```cpp
using Users = table<
    column<"id", int>,
    column<"name", std::string>,
    column<"age", int>
>;
```

2. Compile-time column lookup

Implement the metafunction:
```cpp
column_type_t<Table, "name">
```
which returns the column type.

**Example:**
```cpp
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.

3. SELECT

Implement:
```cpp
query<Table>::select<Cols...>
```
which produces a new schema containing only the selected columns.

**Example:**
```cpp
using Result =
    query<Users>::select<"name", "age">;
```
This must be equivalent to:
```cpp
table<
    column<"name", std::string>,
    column<"age", int>
>;
```
4. WHERE conditions
Implement simple compile-time conditions:
```cpp
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:**
```cpp
using Q = query<Users>::where<greater<"age", 18>>;
```
should compile successfully.

However:
```cpp
using Q = query<Users>::where<greater<"name", 18>>;
```
must fail at compile time.

5. Concepts
Use concepts / requires clauses for:
- validating conditions,
- validating column existence and uniqueness,
- checking type compatibility.

6. fixed_string

Implement support for:
```cpp
template<size_t N>
struct fixed_string;
```
so that it can be used as follows:
```cpp
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](/NPRG051/Zkouška 26.5.2026/ctsql.hpp) into Recodex.

Tests named XXX-SHOULD_FAIL should fail