I want to make this specialized w/o changing main. Is it possible to specialize something based on its base class? i hope so.
-edit-
I'll have several classes inheriting SomeTag. I dont want to write the same specialization for each of them.
class SomeTag {};
class InheritSomeTag : public SomeTag {};
template <class T, class Tag=T>
s...
Consider the following code:
template <int dim>
struct vec
{
vec normalize();
};
template <>
struct vec<3>
{
vec cross_product(const vec& second);
vec normalize();
};
template <int dim>
vec<dim> vec<dim>::normalize()
{
// code to normalize vector here
return *this;
}
int main()
{
vec<3> direction;
directi...
Say you have a class who's job it is to connect to a remote server. I want to abstract this class to provide two versions, one that connects through UDP and the other through TCP. I want to build the leanest runtime code possible and instead of using polymorphism I am considering templates. Here is what I'm envisioning but I'm not sure i...
Consider the following code:
#include <stdio.h>
namespace Foo {
template <typename T>
void foo(T *, int) { puts("T"); }
template <typename T>
struct foo_fun {
static void fun() { foo((T *)0, 0); };
};
}
namespace Foo {
void foo(int *, int) { puts("int"); }
}
using namespace Foo;
int main() {
foo_fun<int> fun;
fu...
i want a specialize template in a pointer-to-member-function case. Is there a way to detect this? right now i declare struct isPtrToMemberFunc, then add an extra template (class TType=void) to each class (right now just 1) and specialize the extra template to see if its isPtrToMemberFunc. Is there a way to detect this automatically? if n...
I have a team of three developers and all three are talented and smart but it has worked out that the professional development of the team is driven by the projects and not any major guiding force. Most major growth is started and encouraged by me (systems head) when it comes to specific technologies.
I know they are willing (and reall...
Considering the following two usage scenarios (exactly as you see them, that is, the end-user will only be interested in using Vector2_t and Vector3_t):
[1]Inheritance:
template<typename T, size_t N> struct VectorBase
{
};
template<typename T> struct Vector2 : VectorBase<T, 2>
{
};
template<typename T> struct Vector3 : VectorBase<T, ...
I have a templated class and inside I have a templated function( different template parameters ) and I having issues getting the compiler to call the correct one.
Example:
template< class Parm1, class Parm2, class Parm3 >
class Class {
public:
void Func( Parm1 arg1, Parm2 arg2 ) {
Call<Parm3>( arg1, arg2 );
}
protected:...
In C++, a function template specialization is supposed to act exactly like a normal function. Does that mean that I can make one virtual? For example:
struct A
{
template <class T> void f();
template <> virtual void f<int>() {}
};
struct B : A
{
template <class T> void f();
template <> virtual void f<int>() {}
};
int m...
I'm a programmer specialized in a couple of non-mainstream fields. Think signal processing, DSP, assembler coding, low level graphics, embeddeed systems and so on.
I'm currently looking out for a new employer, and from my experience it's easy to get a job if you manage to find a company that is working in the fields.
They're always hap...
Is there any way to determine the size in bytes of something like
TItem <T> = record
Data : T;
end;
Can I write something like
function TItem <T>.GetByteSize : Integer;
begin
if (T = String) then
Result := GetStringByteSize (Data as String)
else
Result := SizeOf (Data);
end;
or perhaps with the help of specialization?
functi...
It appears to me that C++ does not allow member template specialization in any scope other than namespace and global scope (MS VSC++ Error C3412). But to me it makes sense to specialize a base class's primary member template in the derived class because that is what derived classes do - specialize things in the base class. For instance, ...
Post edited for clarification (original post at the bottom).
I wish to reorganize the R&D staff from horizontal (i.e. specialty or component based) teams to vertical (i.e. feature, self sufficient) teams. I'm likely to end up with 3-4 teams, with developers and QA engineers who collaboratively can work with most aspects of the product. ...
Can any one please tell, whether below is legal c++ or not ?
template < typename s , s & (*fn) ( s * ) >
class c {};
// partial specialization
template < typename s , s & (*fn) ( s * ) >
class c < s*, s* & (*fn)(s**) {};
g++ ( 4.2.4) error: a function call
cannot appear in a constant-expression
error: template argument 2 ...
How do I make a template specialization that takes 2 parameters versus the normal 1?
I was building a pointer class and now I thought about extending to make an array but if I try something like this:
template<class T,int s> class pointer{};
template<class T> class pointer{};
class mama{};
int main(){
pointer<mama> m;
}
It gives ...
I've worked as an engineer in the mobile industry in Silicon Valley for the past 6 years. I've published a short book about Android and I've written code embedded in millions of handsets.
If I wanted to diversify or movie into a different field, how would I go about it? I know from experience that large scale web engineers make really...
How can I make the genOut/String fire?
module IOStream where
import System.IO
import System.IO.Unsafe
class Out a where
out :: a → String
instance Show a ⇒ Out a where
out = show
outString :: String → String
outString = id
{-# RULES "genOut/String" out = outString #-}
infixl 9 <<, ≪
(≪), (<<) :: Out a ⇒ IO Handle → a → IO Handl...
as a developer, as new technologies come and go quickly, would you specialize in what you are doing or try something new?
for example, I am more inclined towards PHP/Zend Framework development until recently (not that recent) when there’s a lot of Hype abt ASP.NET MVC and Ruby on Rails. I am quite tempted to try those to see if they are...
Hello, noob here still experimenting with templates. Trying to write a message processing class template
template <typename T> class MessageProcessor {
//constructor, destructor defined
//Code using t_ and other functions
foo( void ) {
//More code in a perfectly fine method
}
private: T *t_
};
All defined in a header file. ...
I have the following code (sorry for the large code chunk, but I could not narrow it down any more)
template <bool B>
struct enable_if_c {
typedef void type;
};
template <>
struct enable_if_c<false> {};
template <class Cond>
struct enable_if : public enable_if_c<Cond::value> {};
template <typename X>
struct Base { enum { value ...