traits

In lieu of trait arguments

旧城冷巷雨未停 提交于 2019-12-08 07:59:51
问题 Here's what I want to write: val alg10 = new GeneticAlgorithm[FlatDesign] with PhenotypeSize(10) with FlatDesignMutator with ChildrenReplaceParents(numChildren=2) with TargetFitnessFunction(targetPhenotype) with PopulationSize(40) with RunLength(numGenerations=100) In other words, there are lots of constraints and parameters I'd like to set. For example, PhenotypeSize(10) has implications for the mutator and the fitness function. Abstract types ought to make it easy to implement/enforce all

Is this the correct way of translating Java interface into Scala?

纵然是瞬间 提交于 2019-12-08 07:02:49
问题 I am starting to learn Scala and I will do a simple cross compiler. I will support a small set of instructions like print. Note: the code snippets are not tested or compiled. Here is what I would do in JAVA. public interface Compiler{ String getPrintInstruction(); } public class JavaCompiler implements Compiler{ public String getPrintInstruction(){ return "System.out.print(arg0);" } } public class ScalaCompiler implements Compiler{ public String getPrintInstruction(){ return "print(arg0);" }

enabled_when listening outside model object

和自甴很熟 提交于 2019-12-08 05:24:49
问题 I found a workaround to my original problem but I am hoping someone else can explain what is going on. I originally noticed that enabled_when , and I'd imagine visible_when also, appears to take effect in response to trait events originating from the model object only. If the event originates from some other object, even if the editor refers to it, it doesn't seem to be propagated correctly. class DirectObjectPronoun(HasTraits): text=Str typable=Bool(False) traits_view=View( Item(name=

Extending built-in collections, issues with built-in methods

雨燕双飞 提交于 2019-12-08 03:59:42
问题 I am a Scala novice so forgive me if this is a stupid question, but here goes... Imagine I wish to create an extended Map type that includes additional methods. I can see a few ways to do this. The first would be with composition: class Path[V](val m: Map[V, Int]) { // Define my methods } Another would be via inheritance, e.g. class Path[V] extends Map[V, Int] { // Define my methods } Finally, I've also considered the "trait" route, e.g. trait Path[V] extends Map[V, Int] { // Define my

how to get the size of the padding at the end of a class

倖福魔咒の 提交于 2019-12-08 03:02:26
I have a class A like this: struct V { virtual void f() = 0; }; struct A { int data; }; struct B : public A , public V { void f() override {} }; MSVC gives me sizeof(A) == 4 and sizeof(B) == 16 on a 64 bit build instead of 12 ( sizeof(void*) + sizeof(A) ) - so there is a 4 byte padding. Is there a way to get that padding? perhaps with some trait? The reason I need this is to do an assert like this: static_assert(sizeof(B) == sizeof(A) + std::is_polymorphic<camera>::value * sizeof(void*)); Meaning that I want to ensure that all data is in the base class, but B should be able to be polymorphic

Implicit Conversions on Generic Trait

你离开我真会死。 提交于 2019-12-08 00:13:27
问题 I am implementing a datastructure and want the user to be able to use any type as key as long as he provides a suitable key type wrapping it. I have a trait for this key type. The idea is to have implicit conversions from base to key type and the other way round to (virtually) just use the base type. The trait looks like this: trait Key[T] extends Ordered[Key[T]] { def toBase : T // Further stuff needed for datastructure... } object Key { implicit def key2base[T](k : Key[T]) : T = k.toBase }

Type trait for strings

你说的曾经没有我的故事 提交于 2019-12-07 14:20:12
问题 Is there an existing (in the standard library or in Boost) type trait to test whether a type could represent a string? I stumbled upon an issue when using Boost.Fusion: auto number = fusion::make_vector( 1, "one" ); auto numberName = fusion::filter< char const * >( number ); assert( numberName == fusion::make_vector( "one" ) ); // fails I hoped filter would retain "one", but it failed because "one" is not decayed to a pointer ( make_vector takes its arguments by reference, so the type is

Disable a function by throwing error at compile-time with template class using traits

谁说我不能喝 提交于 2019-12-07 14:06:35
问题 I have a class, let's call it Foo with several methods: template<typename T> class Foo { public: Foo() { /* ... */ } bool do_something() { /* ... */ } // This method should be callable only if: // std::is_floating_point<T>::value == true void bar() { // Do stuff that is impossible with integer } }; I would like to be able to construct both Foo<double> and Foo<int> But I don't want to allow calls to bar() when the type T is not a floating point type. I also want the error to be generated at

Anyone know of a PHP Magic Constant for Trait's Redefined Name in a Class?

不羁岁月 提交于 2019-12-07 13:48:42
问题 To make it simple, I have noticed that PHP doesn't seem to offer any magic constant for determining what the name that a trait has been changed to in a class. Since this sounds confusing to me in words, I will give an example, as it is rather easy and would expect it to be somewhere in the new PHP 5.5, I don't see a way to doing it. So here it is: Say we have some class, that uses some trait that conflicts with some function inside the class, example: class SomeClass { use \Name\Space

Converting GUI-application into .exe-file with cx_Freeze: no plugin found for toolkit qt4

こ雲淡風輕ζ 提交于 2019-12-07 12:43:33
问题 My program contains mayavi, traits and pyqt5 elements in order to visualize something in 3D. I tried to convert my GUI-Application with cx_Freeze and it created the exe-file ,but running it I got the error: no traitsui.toolkits plugin found for toolkit qt4 After some google and stackoverflow research I figured out that it might has something to do with my environment: see creating standalone exe using pyinstaller with mayavi import According to the suggestions in further google research I