xtd 0.2.0
Loading...
Searching...
No Matches
value_type.hpp
Go to the documentation of this file.
1
4#pragma once
5#define __XTD_STD_INTERNAL__
7#undef __XTD_STD_INTERNAL__
8#include "raw_type.hpp"
9#include <concepts>
10#include <iostream>
11#include <type_traits>
12#if defined(__xtd__cpp_lib_format)
13#include <format>
14#endif
15
17namespace xtd {
19
33 template<typename type_t>
34 struct value_type {
36
39 using native_type = type_t;
41
43
46 constexpr value_type() noexcept = default;
49 template<typename other_t>
50 requires std::is_same_v<xtd::raw_type<other_t>, native_type> && (!std::is_same_v<xtd::raw_type<other_t>, value_type>)
51 constexpr value_type(other_t&& value) noexcept : __t__ {value} {}
53
55 template<typename other_t>
56 requires std::is_same_v<xtd::raw_type<other_t>, native_type> && (!std::is_same_v<xtd::raw_type<other_t>, value_type>)
57 value_type& operator =(other_t&& value) noexcept {__t__ = value; return *this;}
58 [[nodiscard]] constexpr operator native_type() const noexcept {return __t__;}
59 native_type __t__ {};
61 };
62
63
65 template<typename type_t>
66 std::ostream& operator <<(std::ostream& os, const xtd::value_type<type_t>& v) {return os << v.__t__;}
67 inline std::ostream& operator <<(std::ostream& os, const xtd::value_type<bool>& v) {return os << (v ? "true" : "false");}
69}
70
73#if defined(__xtd__cpp_lib_format)
74template<typename type_t>
75struct std::formatter<xtd::value_type<type_t>> : std::formatter<type_t> {auto format(const xtd::value_type<type_t>& v, format_context& ctx) const {return std::formatter<type_t>::format(v.value, ctx);}};
76template<>
77struct std::formatter<xtd::value_type<bool>> : std::formatter<bool> {auto format(const xtd::value_type<bool>& v, format_context& ctx) const {return v ? "true" : "false";}};
78#endif
xtd::string format(const xtd::string &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition format.hpp:21
std::remove_cvref_t< value_t > raw_type
Represents a raw type alias equivalent to std::remove_cvref_t<value_t>.
Definition raw_type.hpp:25
@ v
The V key.
Definition console_key.hpp:130
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
std::add_cv_t< type_t > value_type
Represents the read_only_span value type.
Definition read_only_span.hpp:60
Contains xtd::raw_type alias.
type_t native_type
Represents the native type.
Definition value_type.hpp:39
constexpr value_type() noexcept=default
Create a new instance of the value_type.