templates

Output the type of a typedef at compile time in C++ (specifically when an error occurs)

≡放荡痞女 提交于 2021-02-18 12:27:48
问题 It is very difficult for me to explain this particular problem/question so please bear with me (I am having trouble with all my template related questions!). Take this code as an example (note that the point of showing the code is to show a complex template hierarchy, not whether it makes sense): #include <string> #include <vector> #include <list> template <typename T> struct Foo { typedef typename T::value_type value_type; typedef typename T::value_type1 value_type1; typedef typename T:

Golang template range newline removal

别来无恙 提交于 2021-02-18 12:08:29
问题 I'm trying to figure out how I can remove the new lines in my template that are put there by the {{range}} and {{end}}. I get the following output without any of the "-" tags: type {{makeGoTableName .TableName}} struct { {{range $key, $value := .TableData}} {{makeGoColName $value.ColName}} {{$value.ColType}} `db:"{{makeDBColName $value.ColName}}",json:"{{$value.ColName}}"` {{end}} } Results in: type Dogs struct { ID int64 `db:"id",json:"id"` DogNumber int64 `db:"dog_number",json:"dog_number"`

Golang template range newline removal

这一生的挚爱 提交于 2021-02-18 12:07:49
问题 I'm trying to figure out how I can remove the new lines in my template that are put there by the {{range}} and {{end}}. I get the following output without any of the "-" tags: type {{makeGoTableName .TableName}} struct { {{range $key, $value := .TableData}} {{makeGoColName $value.ColName}} {{$value.ColType}} `db:"{{makeDBColName $value.ColName}}",json:"{{$value.ColName}}"` {{end}} } Results in: type Dogs struct { ID int64 `db:"id",json:"id"` DogNumber int64 `db:"dog_number",json:"dog_number"`

Qt: construct a mutable iterator for template (maps, lists, sets, …)

人盡茶涼 提交于 2021-02-18 11:29:45
问题 In my code I often have functions doing the same thing on different iterable Qt Container types, for instance: void removeX(QMap<qint64, QString> & map) { QMutableMapIterator<qint64, QString> it(map); while (it.hasNext()) { it.next(); if (it.value() == "X") it.remove(); } } void removeX(QList<QString> & list) { QMutableListIterator<QString> it(list); while (it.hasNext()) { it.next(); if (it.value() == "X") it.remove(); } } (and I know there is already a removeAll function in QList. This is

friend declaration of template specialization fails

爷,独闯天下 提交于 2021-02-18 11:16:48
问题 The following code containing friend declaration fails with indicated error (see http://ideone.com/Kq5dy): template<class T> void foo() {} template<typename T> class A { void foo(); friend void foo<T>(); // error: variable or field 'foo' declared void }; int main() { foo<int>(); } If the order of friend declaration and member function declaration reversed, then the code compiles without problems (see http://ideone.com/y3hiK): template<class T> void foo() {} template<typename T> class A {

Is it possible to match recursively integer template parameters in C++?

∥☆過路亽.° 提交于 2021-02-18 11:11:51
问题 I have the following problem. I define a N dimensional vector as so #include <vector> #include <utility> #include <string> template <int N, typename T> struct NVector{ typedef std::vector<typename NVector<N-1,T>::type> type; }; template <typename T> struct NVector<1,T> { typedef std::vector<T> type; }; I wish to write a higher order function Map that can transform the leaf elements of the nested vector no matter how deep and return a new nested vector of the same shape. I have tried template

Is it possible to match recursively integer template parameters in C++?

僤鯓⒐⒋嵵緔 提交于 2021-02-18 11:11:26
问题 I have the following problem. I define a N dimensional vector as so #include <vector> #include <utility> #include <string> template <int N, typename T> struct NVector{ typedef std::vector<typename NVector<N-1,T>::type> type; }; template <typename T> struct NVector<1,T> { typedef std::vector<T> type; }; I wish to write a higher order function Map that can transform the leaf elements of the nested vector no matter how deep and return a new nested vector of the same shape. I have tried template

Django Global base.html template

纵饮孤独 提交于 2021-02-18 10:59:19
问题 I am new to Django. I am using Django 1.8.6 with Python 2.7. I am trying to use a base.html template that can be used globaly through out the entire site, where every app and access it. Here is my test site's current structure: twms polls migrations static templates project migrations static templates project index.html tmws static templates tmws base.html Here is the code for project/templates/project/index.html {% extends 'tmws/base.html' %} {% block content %} <h1>Projects</h1> <ul> {% for

How to detect if a class has member variables?

吃可爱长大的小学妹 提交于 2021-02-18 10:57:25
问题 Problem I would like to detect if a class has member variables and fail a static assert if they do. Something like: struct b { int a; } static_assert(!has_member_variables<b>, "Class should not contain members"). // Error. struct c { virtual void a() {} void other() {} } static_assert(!has_member_variables<c>, "Class should not contain members"). // Fine. struct d : c { } static_assert(!has_member_variables<d>, "Class should not contain members"). // Fine. struct e : b { } static_assert(!has

Explicitly use defaults for some parameters in class template instantiation

半世苍凉 提交于 2021-02-18 08:56:30
问题 A class template can have multiple parameters that all have defaults. template<typename UnderlyingT0 = int, typename UnderlyingtT1 = long, typename StringT = std::string> struct options; Instatiating the template with just default parameters is easy: options<> my_default_options; But what if I want to change a subset of parameters? options<int, int, std::wstring> wstring_options; It is not obvious that int is a default for the first parameter while for the second it isn't. Is there something