Skip to content

Commit

Permalink
Add xtd::converter delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
gammasoft71 committed Jan 31, 2025
1 parent 4961b5b commit 7e2813a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/xtd.core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ add_sources(
include/xtd/convert_pointer
include/xtd/convert_string.hpp
include/xtd/convert_string
include/xtd/converter.hpp
include/xtd/converter
include/xtd/cpp_language.hpp
include/xtd/cpp_language
include/xtd/ctrace.hpp
Expand Down
2 changes: 2 additions & 0 deletions src/xtd.core/include/xtd/converter
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#pragma once
#include "converter.hpp"
31 changes: 31 additions & 0 deletions src/xtd.core/include/xtd/converter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/// @file
/// @brief Contains xtd::converter delegate.
/// @copyright Copyright (c) 2025 Gammasoft. All rights reserved.
#pragma once
#include "delegate.hpp"
#include "int32.hpp"

/// @brief The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
namespace xtd {
/// @brief Represents a method that converts an object from one type to another type.
/// ```cpp
/// template<class output_t, class input_t>
/// using converter = xtd::delegate<output_t(input_t)>;
/// ```
/// @par Header
/// ```cpp
/// #include <xtd/converter>
/// ```
/// @par Namespace
/// xtd
/// @par Library
/// xtd.core
/// @ingroup xtd_core system
/// @tparam input_t The type of object that is to be converted. This type parameter is contravariant. That is, you can use either the type you specified or any type that is less derived.
/// @tparam output_t he type the input object is to be converted to. This type parameter is covariant. That is, you can use either the type you specified or any type that is more derived.
/// @param input The object to convert.
/// @return The `output_t` that represents the converted `input_t`.
/// @remarks This delegate is used by the xtd::array::convert_all method of the xtd::array class and the xtd::collections::generic::list::convert_all method of the xtd::collections::generic::list <type_t> class to convert each element of the collection from one type to another.
template<class output_t, class input_t>
using converter = xtd::delegate<output_t(input_t)>;
}
1 change: 1 addition & 0 deletions src/xtd.core/include/xtd/xtd.core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@
#include "convert.hpp"
#include "convert_pointer.hpp"
#include "convert_string.hpp"
#include "converter.hpp"
#include "core_export.hpp"
#include "cpp_language.hpp"
#include "ctrace.hpp"
Expand Down

0 comments on commit 7e2813a

Please sign in to comment.