generic-programming

How to verify the (generic (generic argument))?

拟墨画扇 提交于 2019-12-01 09:05:15
问题 Background (that we don't really need to worry about) This is a question derived from Build A Generic Tree With Inheritance . I open this one as a separate question because this is not only related to a Tree problem. This is more a Generic and Class problem instead. Question To be better illustrated by codes, we have a Tree class, a SubTree class, and a WrongSubTree class: class Tree<TREE extends Tree<?,?>, DATA> { } class SubTree<STREE extends SubTree<?,?>, DATA> extends Tree<STREE, DATA> {

What does <T> T mean when used as a method signature? Is it a return type?

对着背影说爱祢 提交于 2019-12-01 08:08:54
abstract public <T> T iterEdges(EdgeFun<T> func, T accum); This is for a multithreaded library for graphs. I am not asking for anything pertinent to actual implementation whatsoever, I just don't understand what the double return types mean? I am just guessing here, but this is my interpretation (I tried googling, but Google doesn't match on non alphanumeric symbols, so I tried a few combinations of terms but didn't get anywhere.) It is just saying that it will return some kind of collection of T type? Two classes extend the class that this method is found within, and so I guess it allows for

Error calling template method in “templated-base-class”

泄露秘密 提交于 2019-12-01 07:41:14
问题 The following code does not compile, why is that? And how can I fix this? struct A{ template<int N> int get() { return N; } }; template <typename X> struct B : public X { template<int N> int get() { return X::get<N>(); } }; int main(int argc, const char *argv[]) { B<A> b; return b.get<5>(); } Compiler error: test.cxx: In member function ‘int B<X>::get()’: test.cxx:8:30: error: expected primary-expression before ‘)’ token test.cxx: In member function ‘int B<X>::get() [with int N = 5, X = A]’:

What does <T> T mean when used as a method signature? Is it a return type?

和自甴很熟 提交于 2019-12-01 05:44:43
问题 abstract public <T> T iterEdges(EdgeFun<T> func, T accum); This is for a multithreaded library for graphs. I am not asking for anything pertinent to actual implementation whatsoever, I just don't understand what the double return types mean? I am just guessing here, but this is my interpretation (I tried googling, but Google doesn't match on non alphanumeric symbols, so I tried a few combinations of terms but didn't get anywhere.) It is just saying that it will return some kind of collection

Calling method of same name from different class

徘徊边缘 提交于 2019-12-01 05:13:41
问题 I have some classes those have methods with same name. For example public class People { private Long id; private String nm; private String nmBn; ............. public Long getId() { return id; } public String getNm() { return nm; } public String getNmBn() { return nmBn; } } public class Company { private Long id; private String nm; private String nmBn; ............. public Long getId() { return id; } public String getNm() { return nm; } public String getNmBn() { return nmBn; } } Then I need a

Transposing arbitrary collection-of-collections in Scala

与世无争的帅哥 提交于 2019-12-01 03:34:59
I have to often transpose a "rectangular" collection-of-collections in Scala, e.g.: a list of maps, a map of lists, a map of maps, a set of lists, a map of sets etc. Since collections can be uniformly viewed as a mapping from a specific domain to a co-domain (e.g.: a List[A]/Array[A] is a mapping from the Int domain to the A co-domain, Set[A]is a mapping from the A domain to the Boolean co-domain etc.), I'd like to write a clean, generic function to do a transpose operation (e.g.: turn a map of lists to the transposed list of maps). However, I'm having trouble because other than the ()

Developing for Mac OS X, on Windows?

扶醉桌前 提交于 2019-11-30 13:27:15
问题 Well, simple situation. I happen to be a software engineer who uses mostly Delphi and C# for software development. Delphi is great for desktop applications while C# is ideal combined with ASP.NET for web applications. However, I am considering to teach myself more about software development for the Mac. Xcode and Cocoa would be the environments to start with. Learning new languages is no problem for me! However, before starting to write code on a Mac, I first need to buy one and they're

How do I build gcc with C++ concepts (“concepts lite”) support?

烂漫一生 提交于 2019-11-30 10:45:28
The C++ standards committee is working on a TS (Technical Specification) for Concepts extension: "Programming Languages - C++ Extensions for Concepts". N4377 is the latest version of this document. For inclusion into the C++ standard features are asked to be implemented, ideally for a publicly accessible system. I'm aware of concept-gcc but the concepts proposal above (colloquially referred to as Concepts Lite ) is different. I heard that there is a concepts branch and I have tried the origin/asutton/c++-concepts from gcc 's git mirror but that didn't compile. How do I build and use a version

How to resolve generic type of property value from decorated property in decorator

一曲冷凌霜 提交于 2019-11-30 09:49:53
问题 I'm playing with some code, which resolve generic type of property value and doesn't allow provide wrong value. But when I change from TValue to (t: TValue) => TValue , type TValue doesn't going resolved more. It's now unknown {} type, not number more Example without function. Working good type ProtoOf<T> = Pick<T, keyof T>; function decorate<TValue>(value: TValue) { return <T extends { [KA in TKey]: TValue }, TKey extends keyof T>( proto: ProtoOf<T> & { [P in TKey]: TValue }, propertyKey:

Developing for Mac OS X, on Windows?

烈酒焚心 提交于 2019-11-30 07:12:52
Well, simple situation. I happen to be a software engineer who uses mostly Delphi and C# for software development. Delphi is great for desktop applications while C# is ideal combined with ASP.NET for web applications. However, I am considering to teach myself more about software development for the Mac. Xcode and Cocoa would be the environments to start with. Learning new languages is no problem for me! However, before starting to write code on a Mac, I first need to buy one and they're reasonable expensive so buying one is a decision that will take me a few months before I know which one I