generic-programming

Where do you find templates useful?

At my workplace, we tend to use iostream, string, vector, map, and the odd algorithm or two. We haven't actually found many situations where template techniques were a best solution to a problem. What I am looking for here are ideas, and optionally sample code that shows how you used a template technique to create a new solution to a ...

How do you do generic programming in Haskell?

Coming from C++, I find generic programming indispensable. I wonder how people approach that in Haskell? Say how do write generic swap function in Haskell? Is there an equivalent concept of partial specialization in Haskell? In C++, I can partially specialize the generic swap function with a special one for a generic map/hash_map cont...

'Multipurpose' linked list implementation in pure C

( if you get easily bored reading long posts, you can focus on the bold parts ) Hello all! This is not exactly a technical question, since I know C kind of enough to do the things I need to (I mean, in terms of not 'letting the language get in your way'), so this question is basically a 'what direction to take' question. Situation is: ...

What undergraduate computer science course best prepares programmers for the workplace?

The idea here is to get better programmers right out of college. I think I would have to go with Algorithms, it's not exactly something you can pick up on your own very easily and I think it enables you to look at efficiency and correctness of software on a deeper level. I also believe that teaching actual programming can be helpful, b...

When/Why ( if ever ) should i think about doing Generic Programming/Meta Programming

Hi there IMHO to me OOPS, design patterns make sense and i have been able to apply them practically. But when it comes to "generic programming /meta programming" of the Modern C++ kind, i am left confused. -- Is it a new programming/design paradigm ? -- Is it just limited to "library development"? If not, What design/coding situatio...

C++ - Generic programming - Type selection

The following fragment returns the next highest power of two for an (assumed unsigned) integer of type T. It does this by shifting the bits repeatedly. For all intents and purposes the unsigned type i used in the bit shifting loop is sufficiently large to represent a (nominally) 65536 bit number. Practically therefore it's fine to lea...

What are concepts?

I've heard all this new (on /.) about C++0x not having concepts anymore, but I have no idea what they are? Can someone explain to me? ...

Inferring the return type of a function or functor in C++

I need to use a function's/functor's returned value without knowing what type it is (that is, as a template). While I could pass it over to a second function without a problem: template <typename T> void DoSomething(T value); ... DoSomething(FunctionWhoseReturnedTypeIsUnknown(...)); I want to use the returned value inline (without ...

Developing for Mac OS X, on Windows?

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 envir...

.NET Generic List<T> Problem, works by design, need work around. Add value instead of reference

I have a List<T> and I need to avoid the behavior I'm about to outline: // assume cls and numberToAdd are parameters passed in. int pos = numberToAdd; List<MyClass> objs = new List<MyClass>(numberToAdd); for(int i = 0; i < numberToAdd; i++) { objs.Add(cls); objs[i].X = -((pos * cls.Width) + cls.Width...

Generic Methods in C#

Generic Methods in general are new to me. Need a method that returns a Collection of a generic type, but also takes a collection of the same generic type and takes Expression<Func<GenericType, DateTime?>>[] Dates parameter. T throughout the following function should be the same type, so right now I was using (simplified version): ...

handling amorphous subsystems in formal software design

People like Alexander Stepanov and Sean Parent vote for a formal and abstract approach on software design. The idea is to break complex systems down into a directed acyclic graph and hide cyclic behaviour in nodes representing that behaviour. Parent gave presentations at boost-con and google (sheets from boost-con, p.24 introduces the ap...

templates problem ('typename' as not template function parameter)

Actually I've a problem with compiling some library with intel compiler. This same library has been compiled properly with g++. Problem is caused by templates. What I'd like to understand is the declaration of **typename** as not template function parameter and variable declaration inside function body example: void func(typename so...

DataTemplate.DataType=Collection<Entity> ?

Is there a way to create a data template that handles a list of items? I have Contact.Phones (EntityCollection) and I want the data template to handle the list - add remove edit etc. Is there a way to set the DataType property of the DataTemplate to generic EntityCollection? ...

Good introduction to generics

Being compelled by the advantages I'm looking for a way to integrate generic programming into my current programming style. I would like to use generics in C# but can't find any good introductory material with some everyday examples of use. If you have experience with generics: what resources did you find most useful learning them? (book...

Checking for list membership using the STL and a unary function adapted functor

I've attempted to write a brief utility functor that takes two std::pair items and tests for their equality, but disregarding the ordering of the elements. Additionally (and this is where I run into trouble) I've written a function to take a container of those std::pair items and test for membership of a given pair argument in a the cont...

Avoiding boilerplate when dealing with many unrelated types

I'm writing code that deals with values from Language.Exts.Annotated.Syntax, where a variety of types are defined that mirror the structure of a Haskell module: data Module l = ... data Decl l = ... data Exp t = ... -- etc I'd like to be able to write functions that walk these data structures and perform various transformations on the...

Ambiguous type variable

Related to my earlier question on traversing data structures, I'm having a problem making my code generic when I use it along with the uniplate package. I'm dealing with the data structures in the Language.Exts.Annotated.Syntax module, which are all generic with a type parameter l. This l is the same throughout the tree. The kind of cod...

Java generic class and wildcards

Hi all, I've got a problem with generic classes in java. I've got this class: public abstract class MyMotherClass<C extends AbstractItem> { private C item; public void setItem(C item) { this.item = item; } public C getItem() { return item; } } An implementation of this class can be: public...

Java: Integer obj can't cast to Comparable

I'm having problems trying to pass an Integer object from a driver class as an argument for function of a SortedArray Generic class I created. From my driver class, I convert the user's int input into an Integer object to be cast onto Comparable of my SortedArray class. I continue to receive the error: "Exception in thread "main" java.l...