CppXAML
Loading...
Searching...
No Matches
Functions
cppxaml::utils Namespace Reference

Various utilities. More...

Functions

auto tolower (std::wstring_view sv)
 
template<template< typename... > typename TOutContainer = std::vector, typename TInContainer , typename UnaryOp >
auto transform (TInContainer const &iterable, UnaryOp &&unary_op)
 Maps each element in a container via a unary operation on each element.
 
template<template< typename... > typename TOutContainer = std::vector, typename TInContainer , typename UnaryOp >
auto transform_with_index (TInContainer const &iterable, UnaryOp &&unary_op)
 Maps each element in a container via a unary operation on each element.
 

Detailed Description

Various utilities.

Function Documentation

◆ tolower()

auto cppxaml::utils::tolower ( std::wstring_view  sv)
inline
Parameters
sv
Returns

◆ transform()

template<template< typename... > typename TOutContainer = std::vector, typename TInContainer , typename UnaryOp >
auto cppxaml::utils::transform ( TInContainer const &  iterable,
UnaryOp &&  unary_op 
)

Maps each element in a container via a unary operation on each element.

Template Parameters
TOutContainerThe output container type. Defaults to std::vector.
TInContainerThe type of the container
UnaryOpLambda type
Parameters
iterableThe container
unary_opThe lambda for the unary operation; takes the element type of the input container.
Returns
A container comprised of the mapped elements

Example:

◆ transform_with_index()

template<template< typename... > typename TOutContainer = std::vector, typename TInContainer , typename UnaryOp >
auto cppxaml::utils::transform_with_index ( TInContainer const &  iterable,
UnaryOp &&  unary_op 
)

Maps each element in a container via a unary operation on each element.

Template Parameters
TOutContainerThe output container type. Defaults to std::vector.
TInContainerThe type of the container
UnaryOpLambda type
Parameters
iterableThe container
unary_opThe lambda for the unary operation; takes the element type of the input container, and the index within the container.
Returns
A container comprised of the mapped elements

Example:
Here we can define a Grid with Buttons, each of whose content is sourced from a string vector:

auto strs = std::vector<std::wstring>{ L"first", L"second", L"third", L"fourth" };
auto grid = cppxaml::Grid({"40, *"}, {"Auto, Auto"},
cppxaml::utils::transform_with_index(strs, [](const std::wstring& t, auto index) {
return cppxaml::details::UIElementInGrid{
(int)index / 2,
(int)index % 2,
cppxaml::Button(winrt::hstring(t))
};
})
);
auto transform_with_index(TInContainer const &iterable, UnaryOp &&unary_op)
Maps each element in a container via a unary operation on each element.
Definition: utils.h:100
auto Button(C c)
Creates a Button.
Definition: Controls.h:604
Grid(details::GridRows gr, cppxaml::details::GridColumns gc, TElements &&elems)
Creates a Grid with the specified rows, columns, and children.
Definition: Controls.h:510

Example:

auto strs = std::vector<std::wstring>{ L"first", L"second", L"third", L"fourth" };
auto grid = cppxaml::Grid({"40, *"}, {"Auto, Auto"},
cppxaml::utils::transform_with_index(strs, [](const std::wstring& t, auto index) {
return cppxaml::Button(winrt::hstring(t))
.Set(Grid::RowProperty(), (int)index / 2)
.Set(Grid::ColumnProperty(), (int)index % 2);
};
})
);