Skip to content

kiznit/expected

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

std::expected

This is an implementation of std::expected as proposed in P0323R12.

Follow the proposal as close as possible. Don't try to abstract things like constraints, abstractions are leaky and can be a source of error. Adding all the constraints as specified by the proposal can be very noisy, but it makes it easier to verify that the code matches what the proposal says.

Unit tests provide full code coverage to ensure that every method is working correctly. Hours and hours of hard work work went into writing these unit tests. This was certainly headache-inducing. That being said, I am sure they are mistakes in this code. It is very unlikely I got everything right on the first attempt. Please do log issues on GitHub and feel free to submit pull requests.

Testing is done using different versions of GCC, clang, mingw and MSVC. You can see more details on the GitHub build page.

Features

  • Requires C++ 20 (some might not consider this a feature).
  • Works with or without C++ exceptions enabled.
  • Follows the P0323R12 proposal as closely as possible.
  • Implements the P2505R5 proposal as well.

namespace std

Prior to C++ 20, std::unexpected used to be a function. Major compilers still define it as such in their C++ libraries. Header <expected> implements a workaround using macro trickery. If you get compile-time error related to std::unexpected being a function, ensure that you include <expected> before you include <exception> or any other standard header that includes <exception>. To play it safe, make sure to include <expected> before any other standard header. This is known to work on GCC, clang, mingw and MSVC.

An alternative workaround is to not include <expected> and instead include <kz/expected.hpp>. You can then use namespace kz instead of namespace std. For example, std::expected becomes kz::expected.

TODO

  • Refactor/rewrite unit tests and get to 100% coverage, waiting on final spec
  • Generate code coverage and publish it somewhere?