template-meta-programming

Boost hana get index of first matching

痴心易碎 提交于 2019-12-20 02:46:08
问题 So I am trying to make a library using boost::hana that requires the functionality to get the index of a element based on the value: constexpr auto tup = boost::hana::make_tuple(3_c, boost::hana::type_c<bool>); auto index = get_index_of_first_matching(tup, boost::hana::type_c<bool>); // ^^^^^ would be a boost::hana::int_<1> Is there a possible way to do this? Better yet, is it already in hana and I don't know about it? Thanks for the support! 回答1: Hana does not provide an algorithm to do this

Why are type_traits implemented with specialized template structs instead of constexpr?

末鹿安然 提交于 2019-12-19 16:37:33
问题 Is there any reason why the standard specifies them as template struct s instead of simple boolean constexpr ? In an additional question that will probably be answered in a good answer to the main question, how would one do enable_if stuff with the non-struct versions? 回答1: One reason is that constexpr functions can't provide a nested type member, which is useful in some meta-programming situations. To make it clear, I'm not talking only of transformation traits (like make_unsigned ) that

What does T::* mean in template's parameters?

天大地大妈咪最大 提交于 2019-12-19 11:40:55
问题 Following the article written in here: I came across this code (shortened and changed for clarity): template <class T> struct hasSerialize { // This helper struct permits us to check that serialize is truly a method. // The second argument must be of the type of the first. // For instance reallyHas<int, 10> would be substituted by reallyHas<int, int 10> and works! // reallyHas<int, &C::serialize> would be substituted by reallyHas<int, int &C::serialize> and fail! // Note: It only works with

VB.NET Renaming File and Retagging / Edit Image MetaData / Meta Tags

隐身守侯 提交于 2019-12-19 04:04:35
问题 Clarifiration: How do I Edit and Save Image EXIF / Metadata / FileInfo without using an external DLL? Project: I'm building an app for personal use to rename, retag, and organize the apocalyptic quantity of images I host on my personal website. As I have been collecting funny pictures and such for several years, there is no real rhyme or reason to the file naming conventions. Ergo, Image0001.jpg needs to be renamed to a descriptive filename, and the Metadata fields need to be filled in. The

Choose function to apply based on the validity of an expression

房东的猫 提交于 2019-12-18 14:16:20
问题 The problem is the following, in C++14 : Let's have two functions FV&& valid_f , FI&& invalid_f , and arguments Args&&... args The function apply_on_validity should apply valid_f on args if the expression std::forward<FV>(valid_f)(std::forward<Args>(args)...) is valid Otherwise and if std::forward<FV>(invalid_f)(std::forward<Args>(args)...) is a valid expression, apply_on_validity should apply invalid_f on args Otherwise apply_on_validity should do nothing I guess the code should look like

Check if one set of types is a subset of the other

喜夏-厌秋 提交于 2019-12-18 14:16:15
问题 How can one check if one parameter pack (interpreted as a set) is a subset of another one? So far I only have the frame (using std::tuple), but no functionality. #include <tuple> #include <type_traits> template <typename, typename> struct is_subset_of : std::false_type { }; template <typename ... Types1, typename ... Types2> struct is_subset_of<std::tuple<Types1...>, std::tuple<Types2...>> : std::true_type { // Should only be true_type if Types1 is a subset of Types2 }; int main() { using t1

What are the Differences between C++ Templates and Java/C# Generics and what are the limits? [closed]

▼魔方 西西 提交于 2019-12-18 13:27:56
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I read an interesting Article/Thread/Discussion from here and i got following questions: What are the limitations of Java/C# generics?

Implementation of Vector in C++ [closed]

别等时光非礼了梦想. 提交于 2019-12-18 10:17:32
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . I recently wrote an implementation of STL Vector as a programming exercise. The program compiles but I receive a strange error saying: terminate called

Use of void template argument in early detection idiom implementation

空扰寡人 提交于 2019-12-18 05:56:08
问题 In n4502 the authors describe an early implementation of the detect idiom that encapsulates the void_t trick. Here's its definition along with usage for defining a trait for is_assignable (really it's is_copy_assignable ) template<class...> using void_t = void; // primary template handles all types not supporting the operation: template< class, template<class> class, class = void_t< > > struct detect : std::false_type { }; // specialization recognizes/validates only types supporting the

Create a type list combination of types in C++

眉间皱痕 提交于 2019-12-18 05:44:18
问题 Im trying to create some tool to create a list of types based on combinations of other types. Lets say we have three types struct A{}; struct B{}; struct C{}; I want to get a list of tuples which has every possible combination of N types A,B or C. For a N=2 case, this would be std::tuple<A,A> std::tuple<A,B> std::tuple<A,C> std::tuple<B,A> std::tuple<B,B> std::tuple<B,C> std::tuple<C,A> std::tuple<C,B> std::tuple<C,C> The idea is to create a tuple which holds a container for all those types,