In Scala, what does
trait A <: B
mean? Is it just the same as
trait A extends B
?
Edited to add: I'm familiar with the syntax for type parameters, and what <: means in that context. However, in the above example it would seem to me that A is the name of the trait being declared, not a type parameter.
...
It seems I can use self or this for referring to the mixed-in instance or rather to constraint the mixed-in instance. For instance, are those equivalent?
scala> trait A { self: List[_] => }
defined trait A
scala> trait B { this: List[_] => }
defined trait B
Is this just a convention, or using something different than this provide som...
In Scala, I've seen the constructs
trait T extends S
and
trait T { this: S =>
used to achieve similar things (namely that the abstract methods in S must be defined before an instance may be created). What's the difference between them? Why would you use one over the other?
...
This is a snippet of a class template which is causing compilation errors:
/* Secondary index class */
template<class TKey, class TVal, class key_traits, class val_traits>
template<class TSecKey, class sktraits>
class CBtreeDb<TKey, TVal, key_traits, val_traits>::CDbSecondaryIndex: protected CBtreeDb<TKey, TVal>, public IDeallocateKey
...
This question is related to my last one. I am trying to solve the problem using traits<T> and traits<T*>. Please consider the following code.
template<typename T>
struct traits
{
typedef const T& const_reference;
};
template<typename T>
struct traits<T*>
{
typedef const T const_reference;
};
template<typename T>
class test
{...
I am having a very weird issue with templates. Getting an error error: ‘traits’ is not a template. I couldn't reproduce the issue on a sample test project. But it happens on my project (which is bigger than I can post here).
Anyway, following are the files and usages I have. Anyone have any idea about when this error occurs?
I have the...
I have a traits class that's used for printing out different character types:
template <typename T>
class traits {
public:
static std::basic_ostream<T>& tout;
};
template<>
std::ostream& traits<char>::tout = std::cout;
template<>
std::wostream& traits<unsigned short>::tout = std::wcout;
gcc (g++) version 3.4.5 (yes somewhat old) i...
I currently am adding some features to our logging-library. One of these is the possibility to declare a module-name for a class that automatically gets preprended to any log-messages writing from within that class. However, if no module-name is provided, nothing is prepended. Currently I am using a trait-class that has a static function...
I'm looking for ideas on how to implement a Mixin/Trait style system in AS3.
I want to be able to compose a number of classes together into a single object. Of course this is not a language level feature of AS3, but I'm hoping that there is maybe some way to do this using prototype based techniques or maybe some bytecode hacking that I...
C++0x has deprecated the use of old binders such as bind1st and bind2nd in favor of generic std::bind. C++0x lambdas bind nicely with std::bind but they don't bind with classic bind1st and bind2nd because by default lambdas don't have nested typedefs such as argument_type, first_argument_type, second_argument_type, and result_type.
So I...
I observed some inconsistency between two compilers (g++ 4.5, VS2010 RC) in the way they match lambdas with partial specializations of class templates. I was trying to implement something like boost::function_types for lambdas to extract type traits. Check this for more details.
In g++ 4.5, the type of the operator() of a lambda appears...
HI Could anyone give a sample program to implement the is_same_type type trait in c++?
...
I am reluctant to say I can't figure this out, but I can't figure this out. I've googled and searched Stack Overflow, and come up empty.
The abstract, and possibly overly vague form of the question is, how can I use the traits-pattern to instantiate member functions? [Update: I used the wrong term here. It should be "policies" rather ...
The following lines work when I enter them by hand on the Scala REPL (2.7.7):
trait myTrait {
override def toString = "something"
}
implicit def myTraitToString(input: myTrait): String = input.toString
object myObject extends myTrait
val s: String = myObject
However, if I try to compile file with it I get the following error:
[erro...
I've got a Moose class with a lazy_build attribute. The value of that attribute is a function of another (non-lazy) attribute.
Suppose somebody instantiates the class with a value of 42 for the required attribute. Then they request the lazy attribute, which is calculated as a function of 42. Then, they have the nerve to change the first...
Given two independent traits:
trait T1 {
def x = 42
}
trait T2 {
def x = 0
}
If I try to define a class mixing in these two traits like:
class C extends T1 with T2
I get a compiler error:
error: overriding method x in trait T1 of type => Int;
method x in trait T2 of type => Int needs `override' modifier
class C extends T1...
A colleague of mine told me about a little piece of design he has used with his team that sent my mind boiling. It's a kind of traits class that they can specialize in an extremely decoupled way.
I've had a hard time understanding how it could possibly work, and I am still unsure of the idea I have, so I thought I would ask for help her...
And more specific example:
abstract trait A
trait B extends A
trait C extends A
How to check what traits that extend trait A (it can be from 0 to many) were mixed in specified class?
...
Given an instance of a class, we can obviously return its name:
trait MixedInClassDiscovery {
val className = this.getClass.getName
}
class AClass extends MixedInClassDiscovery {
...
this.className // returns "AClass"
...
}
But this way uses reflection, once for every instance of AClass. Can the same be done once for every cl...
I am looking to define a template class whose template parameter will always be an integer type. The class will contain two members, one of type T, and the other as the unsigned variant of type T -- i.e. if T == int, then T_Unsigned == unsigned int. My first instinct was to do this:
template <typename T> class Range {
typedef unsign...