Skip to content

Commit

Permalink
add safe_cast
Browse files Browse the repository at this point in the history
  • Loading branch information
lukevalenty committed Feb 15, 2024
1 parent 57a9b32 commit a09637f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/safe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
#include <safe/object.hpp>
#include <safe/value.hpp>
#include <safe/var.hpp>
#include <safe/safe_cast.hpp>
21 changes: 21 additions & 0 deletions include/safe/safe_cast.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once


#include <safe/detail/concepts.hpp>
#include <safe/detail/fwd.hpp>
#include <safe/var.hpp>

#include <concepts>


template<
typename T,
safe::Var F>
requires (
std::is_convertible_v<typename F::value_type, T> and
safe::detail::integral_type<T>::requirement >= F::requirement)
[[nodiscard]] SAFE_INLINE constexpr auto safe_cast(
F const & src
) {
return static_cast<T>(src.unsafe_value_);
}

0 comments on commit a09637f

Please sign in to comment.