c++ – A recursive_transform for std::array with various return type

This is a follow-up question for A recursive_transform for std::vector with various return type. Thanks to G. Sliepen provide further review suggestions. After digging into the topic of achieving a more generic `recursive_transform` function in both various output type and various container type, I still have no simple solution. However, based on G. Sliepen’s answer, the case of the `std::vector`, `std::deque` and `std::list` container types may be resolved. I am trying to implement additional another overload `recursive_transform` function for `std::array`. Here’s my implementation.

``````template<class T, std::size_t S, class F>
auto recursive_transform(std::array<T, S>& input, const F& f)
{
using TransformedValueType = decltype(recursive_transform(*input.cbegin(), f));

std::array<TransformedValueType, S> output;
std::transform(input.cbegin(), input.cend(), output.begin(),
(f)(auto& element)
{
return recursive_transform(element, f);
}
);
return output;
}
``````

The test case of `std::array`:

``````//  std::array<int, 10> -> std::array<std::string, 10>
std::array<int, 10> test_array;
for (int i = 0; i < 10; i++)
{
test_array(i) = 1;
}
auto recursive_transform_result5 = recursive_transform(
test_array,
()(int x)->std::string { return std::to_string(x); });                          //  For testing
std::cout << "string: " + recursive_transform_result5.at(0) << std::endl;
``````

Here’s the Godbolt link. The code in this link including the test cases for `std::vector`, `std::deque` and `std::list`.

All suggestions are welcome.

The summary information:

• Which question it is a follow-up to?

A recursive_transform for std::vector with various return type

• What changes has been made in the code since last question?

The handleable container type in the previous version of `recursive_transform` function is `std:vector`. With G. Sliepen’s answer, this handleable container type list is extended to `std::vector`, `std::deque` and `std::list`. Then, I am trying to deal with `std::array` here.

• Why a new review is being asked for?

In this version of `recursive_transform` function, it seems that working well in the mentioned test case `std::array<int, 10> -> std::array<std::string, 10>`. However, there is some issues when it comes to the more complex case like `std::array<std::array<int, 10>, 10> -> std::array<std::array<std::string, 10>, 10>` (the scalability to be improved!) If there is any suggestion or possible idea about this, please let me know.

mobile – Filter by type of content into specific content

I have some trouble to find a UX pattern that would fit for an mobile app improvement.

I would like to display in the news feed a filter by type of content for example:
News, Event, Project etc…
+ Search bar

(similar to this one)

Moreover I would like to also include this filter + search into specific type of content.

For example, Project can embed (News + Event). So I want to be able to filter News and Event inside “Project”.

The problem is that in my “project” I also want to show a lot of information about the project and I’m not sure it’s a good solution to put the tab bar at the bottom of the infos. Also, I can’t put the filter at the top of my project because it will make no sense to show content before project info.

The main goal is to have quick access to content inside the project and be able to filter it, but also have a quick view of my project info.

What pattern would be the best? Do you have a similar case to show?

I imagine it to be similar to this screen, except I should also be able to filter content into each tab.

dnd 3.5e – What happens when a creature with Racial Hit Dice changes creature type?

The specific example I’m working with is a creature with RHD who takes the Human Heritage feat… and then advances by HD.

The creature retains all the traits of its previous type (so far so good), but what happens to its existing RHD? Do they change to the new type, or stay the same? The SRD says:

…but most templates that change Hit Dice change only the creature’s original HD and leave class Hit Dice unchanged.

However, this is in the context of whether class HD change when there is already an HD change happening, so I don’t know if it should generalize to “HD changing is the default”.

If the creature then advances by gaining more HD, I assume that all the new HD would be of the new type, but I’m open to peoples’ opinions on this as well.

Bridging the two questions, there’s also an argument to be made that since Human Heritage is a 1st level only feat, all RHD are acquired after it is taken, and should thus be of the Humanoid type.

2019 – External Content Type ( BDC ) From MS SQL – Fill multiple Columns from one selection?

SharePoint 2019 on-prem. I have a list with an external column that populates customer numbers from a SQL table. Works great. The lookup column is on customer number and that is populated on the list. The same SQL table also has customer name.

Is there a way to get it to auto populate another column with the name where the customer number = what was chosen in the previous column ?

Hopefully I explained myself well.

graph traversal – Counting paths by their type

An edge-labelled directed graph is the data of $$G = (V, E, l)$$ where $$(V, E)$$ is a directed graph, and $$l colon E to mathbb{P}$$ is some function. (For the graph I am considering, labels take values in $$mathbb{P} = {1, 2, 3, ldots}$$). To any path $$v_0 to v_1 to ldots to v_n$$ in $$G$$, we can associate a type $$alpha = (alpha_1, ldots, alpha_n) in mathbb{P}^n$$, where $$alpha_i = l(v_{i-1}, v_i)$$. For a fixed source vertex $$s$$, destination vertex $$t$$, and type $$alpha in mathbb{P}^n$$, let $$P(s, alpha, t) in mathbb{N}$$ be the number of $$s rightsquigarrow t$$ paths of type $$alpha$$.

I have two counting problems, the first of which I can solve fairly efficiently, and the second of which I am hoping for some assistance. In the problem I am considering, the directed graph is acyclic, and satisfies other interesting properties: for example $$P(s, alpha, t) = P(s, beta, t)$$ whenever $$alpha$$ is a permutation of $$beta$$. Furthermore, in the problem I am consdiering $$G$$ is an infinite graph, but each of the following problems is finite.

Problem 1: Fix a source $$s in V$$ and a type $$alpha$$, and determine all of the numbers $$P(s, alpha, -)$$.

Problem 2: Fix a source $$s in V$$ and a destination $$t in V$$, and determine all of the numbers $$P(s, -, t)$$.

For problem 1, we can take an approach very similar to counting paths in a DAG. Initialise an array $$mathtt{D}$$ indexed by $$V$$ to zero, and set $$mathtt{D}(s) = 1$$. Then perform a breadth-first search, at the first layer following all edges of type $$alpha_1$$, and for each $$s xrightarrow{alpha_1} v$$ increment $$mathtt{D}(v)$$ by $$mathtt{D}(s)$$. Repeat for all the $$alpha_2, ldots, alpha_n$$. At the end, the last layer contains all vertices $$t$$ reachable from $$s$$ via an $$alpha$$-path, and $$mathtt{D}(t)$$ is equal to $$P(s, alpha, t)$$.

Problem 2 is more tricky, and the best strategy I have at the moment is essentially to iterate over the potential allowed types $$alpha$$ and compute each $$P(s, alpha, t)$$ individually. Another approach would be to do a breadth-first-search from $$s$$, but storing at each vertex the path type leading there, together with multiplicity – but this doesn’t seem to be faster.

What is the best way to export a complete content type with fields in Drupal 8?

How can we export a complete content type, including fields, and import it into staging or production?

recursion – A recursive_transform Function For Various Type Nested Iterable With std::variant Implementation in C++

This is a follow-up question for A TransformAll Function For Various Type Arbitrary Nested Iterable Implementation in C++. The following code is the improved version based on G. Sliepen’s answer. In order to match the conventions of the STL, the function named `recursive_transform` here uses the `is_iterable` concept and the `is_element_iterable` concept. Moreover, the copy operation of the input is avoided by updating `(_Func)(auto element)->auto` into `(_Func)(auto& element)` and the redundant part in this lambda function `->auto` has been removed. Although the code is improved, I found that there are some cases which the previous version `TransformAll` function is hard to deal with. One of those cases is the nested iterable ranges with `std::variant`. I want to focus on this case, such as `std::vector<std::variant<long double>>`. First of all, the additional concept `is_element_variant` is included for determining the type of elements in iterable container is `std::variant` or not. I think there may be another better implementation to this `is_element_variant` concept. However, the method I surveyed How to check if template argument is std::variant? isn’t deal with this with c++-concepts. I prefer to work with concept here and the experimental code is as below. If there is any suggestion about how to improve this `is_element_variant` concept, please let me know.

``````template<typename T>
concept is_element_variant = requires(T x)
{
x.begin()->index();
x.begin()->valueless_by_exception();
};
``````

The part of the template function `recursive_transform` which handle the `std::variant` structure:

``````template<class T, class _Fn> requires is_iterable<T> && is_element_variant<T>
static T recursive_transform(const T _input, _Fn _Func);       //  Deal with the iterable case which its element is std::variant

template<class T, class _Fn> requires is_iterable<T> && is_element_variant<T>
static inline T recursive_transform(const T _input, _Fn _Func)
{
T returnObject = _input;

std::transform(_input.begin(), _input.end(), returnObject.begin(),
(_Func)(typename std::iterator_traits<typename T::iterator>::value_type x)->
typename std::iterator_traits<typename T::iterator>::value_type
{
return std::visit((_Func)(auto&& arg) -> typename std::iterator_traits<typename T::iterator>::value_type
{
return _Func(arg);
}, x);
});
return returnObject;
}
``````

The other parts:

``````template<typename T>
concept is_iterable = requires(T x)
{
x.begin();      // must have `x.begin()`
x.end();        // and `x.end()`
};

template<typename T>
concept is_element_iterable = requires(T x)
{
x.begin()->begin();
x.end()->end();
};

template<class T, class _Fn> requires is_iterable<T>
static T recursive_transform(const T _input, _Fn _Func);       //  Deal with the iterable case like "std::vector<long double>"

template<class T, class _Fn> requires is_iterable<T>
static inline T recursive_transform(const T _input, _Fn _Func)
{
T returnObject = _input;

std::transform(_input.begin(), _input.end(), returnObject.begin(), _Func);
return returnObject;
}

template<class T, class _Fn> requires is_iterable<T> && is_element_iterable<T>
static T recursive_transform(const T _input, _Fn _Func);

template<class T, class _Fn> requires is_iterable<T> && is_element_iterable<T>
static inline T recursive_transform(const T _input, _Fn _Func)
{
T returnObject = _input;
std::transform(_input.begin(), _input.end(), returnObject.begin(),
(_Func)(auto& element)
{
return recursive_transform(element, _Func);
}
);
return returnObject;
}

int main()
{
std::vector<long double> testVector1;
testVector1.push_back(1);
testVector1.push_back(20);
testVector1.push_back(-100);
std::cout << recursive_transform(testVector1, ()(long double x)->long double { return x + 1; }).at(0) << std::endl;

std::vector<long double> testVector2;
testVector2.push_back(10);
testVector2.push_back(90);
testVector2.push_back(-30);

std::vector<std::vector<long double>> testVector3;
testVector3.push_back(testVector1);
testVector3.push_back(testVector2);
std::cout << recursive_transform(testVector3, ()(long double x)->long double { return x + 1; }).at(1).at(1) << std::endl;

std::vector<std::variant<long double>> testVector4;
testVector4.push_back(1);
testVector4.push_back(20);
testVector4.push_back(-100);

auto operation_to_element = ()(long double number) { return number + 2; };

std::visit(()(auto&& arg) {std::cout << arg; },         //  For printing
recursive_transform(testVector4, operation_to_element).at(0)
);

return 0;
}
``````

All suggestions are welcome.

The summary information:

• Which question it is a follow-up to?

A TransformAll Function For Various Type Arbitrary Nested Iterable Implementation in C++

• What changes has been made in the code since last question?

• Rename function to `recursive_transform` to match the conventions of the STL.
• The copy operation of the input is avoided by updating `auto &element`.
• Remove the redundant part in lambda function `->auto`
• Why a new review is being asked for?

I think the concept `is_element_variant` may be improved and I am looking forward to any suggestion for possible improvement ways. Moreover, in my opinion of the part of the template function `recursive_transform` which handle the `std::variant` structure, implementation here is complex, there are two nested lambda function. If there is any possible to simplify this, please let me know.

Display category filters for custom post type when category is shared by multiple post types

I already have a solution to this problem but I’m wondering if there’s a more efficient way to do it. I have a custom post type called “galleries” that uses the same taxonomy as blog posts. So if a user creates a category named “Animals” when making a blog post, that category will show up as an option when creating a new gallery.

On the gallery display page, I want to output a list of categories in a select element which are used to filter the galleries. However, if no galleries are using the category “Animals”, that category shouldn’t be displayed, since selecting it will return no results.

Here’s how I solved this so far:

``````<?php
// 1. Get all the categories
\$categories = get_categories( array(
'orderby'   => 'name',
'order'     => 'ASC'
) );
?>

<select>

<?php
// 2. Loop through the categories
foreach(\$categories as \$cat) {

// 3. Get the ID of the current category
\$category_id= get_cat_id(\$cat->name);

// 4. Query the galleries post type for posts using the current category
\$args = array(
'post_type' => 'galleries',
'category' => \$category_id
);
\$posts = get_posts(\$args);

// 5. Count the number of posts using the current category
\$count = count(\$posts);

// 6. Display the option if that number is greater than 0
if(\$count > 0) { ?>

<option value="<?php echo \$cat->slug; ?>"><?php echo \$cat->name; ?></option>

<?php } ?>

</select>
``````

It seems like that’s a lot of steps and maybe I’m doing this in a roundabout kind of way. Is there a more efficient way to do this? Thanks in advance.

wordpress.org – How can I access WooCommerce ‘variations_form’ elements via JavaScript that are generated by a script template type?

I’ve recently customized the WooCommerce variable.php file for a single product to add a custom form text field, supposed to be filled in by buyers on each single product page. I have however failed to access this form field with getElementById(‘element_id’) or jQuery’s selector \$(‘element_id’).

Though the ‘variations_form’ is visible via the browser inspector, it’s actually generated by a JavaScript template type once viewed in the source code.

How can I access the form elements within the variations_form?

Thanks.

comparison – How to properly implement a “compare” operation for Range data type?

Say you have an object that represents a range of numeric values, `Range<T>`, where `T` is a numeric type.

It has a `T upperBound`, a `T lowerBound`, a `bool lowerBoundExclusive`, and `bool upperBoundExclusive`, which represent the lower bound of the range, the upper bound of the range, whether the lower limit is inclusive or exclusive, and whether the upper limit is inclusive or exclusive.

Implementing an equality test on this kind of object is very simple; you just test every value against the other instance’s values.

However, how should one implement a relative ordering of `Range<T>`s? I thought of the following ways of doing this:

• Compare the upper bounds of both instances. If they’re different, return the sign of that comparison. If they’re the same, compare the lower bounds and return the sign of that comparison:

``````int cmp = upperBound.compareTo(other.upperBound);

return (cmp != 0) ? lowerBound.compareTo(other.lowerBound) : cmp;
``````
• Compute the median of both ranges, and compare those:

``````T median = lowerBound + ((upperBound - lowerBound) / 2.0);
T otherMedian = other.lowerBound + ((other.upperBound - other.lowerBound) / 2.0);

return median.compareTo(otherMedian);
``````
• Compare the magnitude of the ranges:

``````return (upperBound - lowerBound).compareTo(other.upperBound - other.lowerBound);
``````

Is there an ‘accepted’ way to order ranges?