template-meta-programming

finding type, for which is_constructible holds

女生的网名这么多〃 提交于 2019-12-01 07:24:34
问题 I was playing around with templates and was trying to implement following helper. first_constructible<Types..., Args...>::type which would return first type of Types which is constructible from Args... . First problem obviously is having two parameter packs in struct , so I changed usage to first_constructible<std::tuple<Types...>, Args...>::type I've implemented it by splitting tuple types as first and rest, checked using std::is_constructible and recursed if neccessary. template<typename T>

boost::mpl::vector - getting to a type's base-offset

拈花ヽ惹草 提交于 2019-12-01 06:43:12
Is it possible to get at the offset of a mpl::vector after performing a mpl::find<seq,type> on it ? Put differently I want to do the compile time equavalent of: #include <vector> #include <algorithm> #include <iostream> int main() { typedef std::vector<int> v_type; v_type v_int(3); v_int[0] = 1; v_int[1] = 2; v_int[2] = 3; v_type::iterator it= std::find( v_int.begin() ,v_int.end(),3); std::cout << it - v_int.begin() << std::endl; } Failing this, my types in mpl::vector have a type_trait<T>::ordinal const hard-coded, I would like to avoid this if possible. Important Note , I am also creating a

boost::mpl::vector - getting to a type's base-offset

那年仲夏 提交于 2019-12-01 05:12:15
问题 Is it possible to get at the offset of a mpl::vector after performing a mpl::find<seq,type> on it ? Put differently I want to do the compile time equavalent of: #include <vector> #include <algorithm> #include <iostream> int main() { typedef std::vector<int> v_type; v_type v_int(3); v_int[0] = 1; v_int[1] = 2; v_int[2] = 3; v_type::iterator it= std::find( v_int.begin() ,v_int.end(),3); std::cout << it - v_int.begin() << std::endl; } Failing this, my types in mpl::vector have a type_trait<T>:

template metafunction for detecting template specialisations

人走茶凉 提交于 2019-12-01 03:46:56
Inspired by this question , i'm wondering if there is some compile-time check one can introduce to detect if two given template instantiations: template <typename T> class Templ... typedef Templ<std::string> stringInstance; typedef Templ<double> doubleInstance; are constructed from the same definition, or if they are built from different specializations of the Templ template so basically the hypothetical template function will behave like this: template <typename T> class Templ {} template <> class Templ<std::string> {} template <> class Templ<double> {} template <typename T1,typename T2>

template metafunction for detecting template specialisations

放肆的年华 提交于 2019-12-01 01:46:04
问题 Inspired by this question, i'm wondering if there is some compile-time check one can introduce to detect if two given template instantiations: template <typename T> class Templ... typedef Templ<std::string> stringInstance; typedef Templ<double> doubleInstance; are constructed from the same definition, or if they are built from different specializations of the Templ template so basically the hypothetical template function will behave like this: template <typename T> class Templ {} template <>

How to know if the argument that is passed to the function is a class, union or enum in c++?

ぃ、小莉子 提交于 2019-12-01 00:49:24
I want to define an operator<< for all enums, to cout the value and print that it is an enum like this: code: enum AnyEnum{A,B,C}; AnyEnum enm = A; cout << enm <<endl; output: This is an enum which has a value equal to 0 I know a way of doing this with Boost library by using is_enum struct. But I don’t understand how it works. So that's why, in general, I am interested how to identify if the veriable is a class type, union type or an enum (in compile time). Determining class types you could use the fact that member pointers exist template<typename A, typename B> struct issame { }; template

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

余生颓废 提交于 2019-11-30 23:18:45
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 desired process will take an existing jpg, gif, png, tiff or bmp and do the following: load image into

c++ generic compile-time for loop

做~自己de王妃 提交于 2019-11-30 23:17:50
问题 In some contexts, it could be useful/necessary to have a for loop evaluated/unrolled at compile time. For example, to iterate over the elements of a tuple , one needs to use std::get<I> , which depends on a template int parameter I , hence it has to be evaluated at compile time. Using compile recursion one can solve a specific problem, as for instance discussed here, here, and, specifically for std::tuple here. I am interested, however, on how to implement a generic compile-time for loop. The

Compile-time recursive function to compute the next power of two of an integer?

孤街醉人 提交于 2019-11-30 21:10:13
On the Bit Twiddling Hacks website the following algorithm is provided to round up an integer to the next power of two: unsigned int v; // compute the next highest power of 2 of 32-bit v v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; I would like to code a metaprogramming function that will compute the same operation: recursively (for compile-time execution) for any kind of integer (it should even work for possible awkward non-standard integers of any size like 15 bits, 65 bits...) and here is the form of the expected function: template <typename Type, // Something

Using `void_t` to check if a class has a method with a specific signature

一曲冷凌霜 提交于 2019-11-30 20:23:31
At the moment, I'm using this method to check if a class has a method with a specific signature. After attending Walter E. Brown's metaprogramming CppCon2014 talk , I started wondering if void_t could be used in this particular situation to make the code cleaner and more readable. However I'm having trouble thinking in terms of void_t - so far I understand that void_t can help me determine at compile-time whether or not an expression is valid. Example: template< class, class = void > struct has_type_data_member : false_type { }; template< class T > struct has_type_data_member<T, void_t