Hello,
I've got a small bit of code from a library that does this:
#define VMMLIB_ALIGN( var ) var
template< size_t M, typename T = float >
class vector
{
...
private:
// storage
VMMLIB_ALIGN( T array[ M ] );
};
And you can call it by doing
//(vector<float> myVector)
myVector.array;
No parenthesis or anything.
what?
Afte...
When compiling this code I get the following error:
In function 'int main()':
Line 11: error: invalid initialization of non-const reference of type 'Main&' from a temporary of type 'Main'
template <class T>
struct Main
{
static Main tempFunction(){
return Main();
}
};
int main()
{
Main<int> &mainReference = Main<int>...
How to check (without Boost or other nonstandard lib) if type passed to template is an enum type?
Thanks.
...
The following std::vector code is giving errors
int main()
{
std::vector<const double> VectDouble;
VectDouble.push_back(2.34);
VectDouble.push_back(2.33);
VectDouble.push_back(2.32);
for(std::vector<const double> VectDouble::iterator i=VectDouble.begin();i!=VectDouble.end();++i)
std::cout<<*i;
}
...
This was motivated by this article (page 5)
template<class T>
T const &f(T const &a, T const &b){
return (a > b ? a : b);
}
template int const &f<int>(int const &, int const &);
int main(){
int x = 0, y = 0;
short s = 0;
f(x, y); // OK
f(x, s); // Is this call well-formed?
}
Is the call 'f(x, s)' well-fo...
I have a need to write a basic scripting/templating engine that will run under PHP. Ideally, I would be able to mix my own markup language with an (X)HTML template and run the document through a server-side parser to dynamically replace my own markup with (X)HTML served out of a database.
Unfortunately, for all my knowledge of PHP and ...
I'd like to add "template items" in tineMCE editor.
The template items act like a placeholder for dynamically inserted data.
An example:
Instead of writing: "Hi {firstname}, you are {years} years old."
I'd like to insert a object instead of the "{firstname}" that gets replaced to "{firstname}" when saving against the server. It shou...
#include "stdafx.h"
#include <iostream>
using std::cout;
template<class T>
class IsPolymorphic
{
template<class T>
struct Check
{
enum {value = false};
};
template<class T>
struct Check<T*>
{
enum {value = true};
};
public:
enum {value = Check<T>::value};
};
template<bool flag, class T, class U>
struct Select
{
typedef...
Hello all,
I would like to know how can I set a variable with another variable in jinja. I will explain, I have got a submenu and I would like show which link is active. I tried this:
{% set active_link = {{recordtype}} -%} where recordtype is a variable given for my template
Thanks,
...
I have an approach to call delayed function for class:
//in MyClass declaration:
typedef void (MyClass::*IntFunc) (int value);
void DelayedFunction (IntFunc func, int value, float time);
class TFunctorInt
{
public:
TFunctorInt (MyClass* o, IntFunc f, int v) : obj (o), func (f), value (v) {}
virtual void operator()();
protected:
...
Can anybody explain me, what is use of vector class? My Professor mentioned about below sentence in the lecture.
Template: Each vector has a class parameter that determines which object type will be used by that instance, usually called T. I don't understand what exactly class parameters means?
...
This is the statement from ISO C++ Standard 14.6/6:
Within the definition of a class template or within the definition of a member of a class template, the keyword typename is not required when referring to the unqualified name of a previously declared member of the class template that declares a type. The keyword typename shall alwa...
My question is w.r.t the following thread : http://stackoverflow.com/questions/2009924/specialize-a-member-template-without-specializing-its-parent
I'm absolutely fine with the standard saying that it is illegal to do so. But i want to understand why is it illegal to do so? What would be impact had it been allowed?
...
Hello,
I have two classes (ClassA and ClassB) who both have two methods (compare and converge). These methods work exactly the same way, but these classes are not related polymorphically (for good reason). I would like to define a function template that both of these classes can explicitly instantiate as a member but I'm getting error...
This is the statement from ISO C++ Standard 14.6/7:
Knowing which names are type names
allows the syntax of every template
definition to be checked. No
diagnostic shall be issued for a
template definition for which a
valid specialization can be generated.
If no valid specialization can be
generated for a template ...
I'm trying to write a function to print a representation of common STL containers (vector, list, etc..). I gave the function a template parameter T which, for example, might represent vector. I'm having problems getting an iterator of type T.
vector<int> v(10, 0);
repr< vector<int> >(v);
...
template <typename T>
void repr(const T & ...
Is it possible?
template<operator Op> int Calc(int a, b)
{ return a Op b; }
int main()
{ cout << Calc<+>(5,3); }
If not, is way to achieve this without ifs and switches?
...
Hello everyone
Modern template engines for php (say, dwoo or smarty) can use objects as variables. You can use {$obj->method()}, which is really convenient, and i am using this a lot.
But, there is a clear security problem with exporting directly objects from ORM, which have methods such as insert, delete etc.
Is there any sane method ...
I am confused about the strange syntax provided by C++ function templates and class templates. Take a quick look at the code below:
#include <iostream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <vector>
using namespace std;
template <class op1,class op2>
class compose_fg_x_t : public unary_function<typena...
What is the use of 'non type template' parameters which are of 'reference' type? Why are such parameters also treated as 'rvalues'?
template<int &n> void f(){
&n; // error
}
int main(){
int x = 0;
f<x>();
}
...