Theme Catppuccin
Make yourself at homeCatppuccin

A softer light for long learning sessions.

Appearance

Loading your preference…

Dark palette

Choose a dark palette to try it.

Light uses Latte. Your choices stay in this browser.

Back to your source shelf

Inside the companion

Modern C++ errors

Follow one pixel through validation, std::expected, and a complete-or-unchanged update.

Project files 6

Build the error-boundary study

C++23 targets, tests, and the optional sanitizer configuration.

34 lines CMakeLists.txt
cmake_minimum_required(VERSION 3.25)
project(PixelBoundary LANGUAGES CXX)
set(CMAKE_CXX_EXTENSIONS OFF)
option(PIXEL_SANITIZE "Enable address and undefined-behavior checks" OFF)

function(pixel_policy target)
  if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
    target_compile_options(${target} PRIVATE -Wall -Wextra -Wpedantic -Wconversion -Wshadow)
    if(PIXEL_SANITIZE)
      target_compile_options(${target} PRIVATE -fsanitize=address,undefined -fno-omit-frame-pointer)
      target_link_options(${target} PRIVATE -fsanitize=address,undefined)
    endif()
  elseif(PIXEL_SANITIZE)
    message(FATAL_ERROR "PIXEL_SANITIZE requires Clang or GCC")
  endif()
endfunction()

add_library(pixel_core src/pixel.cpp)
target_include_directories(pixel_core PUBLIC include)
target_compile_features(pixel_core PUBLIC cxx_std_23)
pixel_policy(pixel_core)
add_executable(pixel-boundary src/main.cpp)
target_link_libraries(pixel-boundary PRIVATE pixel_core)
pixel_policy(pixel-boundary)

include(CTest)
if(BUILD_TESTING)
  add_executable(pixel-tests tests/pixel_tests.cpp)
  target_link_libraries(pixel-tests PRIVATE pixel_core)
  pixel_policy(pixel-tests)
  add_test(NAME expected-contracts COMMAND pixel-tests)
  add_test(NAME expected-demo COMMAND pixel-boundary)
endif()

This is the file included with the course. Copy and download give you its complete source.

Taking your work offline? Download all course companions