Archive

Posts Tagged ‘c++’

Working with traits…

September 22, 2011 3 comments

URGH!

I’m trying to write something along the lines of:


template<typename _ItrType>
static size_t countThings(_ItrType begin, _ItrType end)
{
  size_t numThings = 0 ;
  for ( _ItrType it = begin ; it != end ; ++it )
  {
    Entity& entity = getEntityFromIterator(it) ;
    numThings += entity.numThings ;
  }
}

// Handle associative iterators.
template<typename _KeyType>
Entity& getEntityFromIterator(std::pair<_KeyType, Entity&>& it)
{
  return it.second ;
}

template<typename _KeyType>
Entity& getEntityFromIterator(std::pair<_KeyType, Entity*>& it)
{
  return *(it.second) ;
}

template<typename _KeyType>
Entity& getEntityFromIterator(std::pair<_KeyType, Entity>& it)
{
  return it.second ;
}

// Handle sequence iterators.
template<typename _ItrType>
Entity& getEntityFromIterator(_ItrType& it)
{
  return *it ;
}

I.e. something that will allow me to write a function that will take an iterator range and worry about whether the iterators are sequence or container for me at compile time.

But it always falls thru to my last case. The error from GCC indicates that I need to specifically look ¬†std::_RB_tree_iterator<std::pair<_KeyType, Entity>> etc, but I’d rather not. I’m wanting to do something to peel back until we get to an Entity, e.g.

template<typename _Outer, typename _Inner>get(_Outer<_Inner>& container) { return *container ; }
template<typename _Key, typename _Value> get(_Key, _Value entity) { return get(entity) ; }
get(Entity& entity) { return entity ; }
get(Entity* entity) { Return *entity ; }

Cannot seem to find a way to get this to work, and I’m starting to think I probably need to do some traits jiggery-pokery. Grr.

Categories: Coding Tags: ,

Replacing playgate…

September 3, 2011 4 comments

Of course, there’s way more important things to do but replacing PlayGate is still on the todo list after my .NET rewrite got scratched due to a failure to understand what “this is a development version so it may require you to install various libraries and stuff” mean’t, and I had to keep the old Win32 C code alive, again.

The thing keeping me from resurrecting my .NET version is that either I’m missing something or .NET localization is a total pain in the backside – even with XAML?

 

Categories: Coding Tags: ,

Why “auto” is the wrong keyword.

February 23, 2011 7 comments

C++0x introduces a new keyword, “auto”, for variable declarations which tells the compiler to infer the variable’s type from the assignment expression.

std::list<std::string> foo = getListOfStrings() ;
// becomes
auto foo = getListOfStrings() ;

While this will save a ton of typing, I think it demonstrates some fundamental issues with the way C++ is being advanced – especially when compared with languages like Python, Erlang and C#.

This handy feature exists in other C-derived languages, in particular C# 4.0 has the same feature but the keyword is different, “var”.

The simple fact is: C++ got it wrong.

Read more…

Categories: Coding, Rants & Opinions Tags:

Qualm before the sharp.

February 16, 2011 5 comments

(Forgot to ‘Publish’ this on the weekend. Re the title: I have no idea…)

I like C#. There. I said it.

It blends the feeling of a scripting language with the power of C/C++. Thanks to Mono, it also has some portability (at least, as far as the scripting bit goes).

In some ways its more like Java than C++. Luckily for me, usually in areas that I actually like about Java (such as interfaces, etc). I also tend to find that things that bothered/bother me about C++ are tackled in C#.

While I’m still a C# greenbelt, I can already see some fairly annoying facets, though.

First, foremost and pettiest:

Read more…

Categories: Coding, Rants & Opinions Tags:

Technology Review Agrees

April 25, 2010 Leave a comment

Multicore Processors create software headaches.

I guess my recent post was timely :)

Read more…

Threading Building Blocks intro

April 23, 2010 4 comments

I put together a short video walkthru creating a skeleton Visual Studio 2008 project with Intel’s Threading Building Blocks that introduces the basics of using Threading Building Blocks and compares performance of serial and parallel sort.

Read more…

“DBA” v0.1

March 2, 2010 Leave a comment

http://www.kfs.org/~oliver/dba/

The MySQL interface is working, I wouldn’t call it complete. The SQLite interface is what I was going to work on tonight, I’ll see if I can get it working tomorrow.

Todo List:

  1. Get SQLite interface functioning,
  2. Unit tests,
  3. Windows and Mac,
  4. Auto-documentation,
  5. Convenience constructors,
  6. Source control,
  7. Add a Postgres interface,
  8. Features (such as parameter binding, column metadata retrieval),
  9. .NET API

That list will definitely grow :)

Notes on the development below:

Read more…

C++ Templates, avoiding virtual

February 28, 2010 17 comments

I’ve not done a great deal with C++ Templates, and especially with some of the improvements in C++0x, I’m thinking I’d like to change that.

One particular example I’m tinkering with right now is a database abstraction layer I’ve been dragging around with me for years. It has two primary members: DBQuery and DBRow. Up until now they have been littered with #ifdef’s. I want to ditch the ifs and switch to templates.

Read more…

Categories: Coding Tags: , ,

Mono vs Java

February 24, 2010 16 comments

There is a slowly emerging community of .NET developers for Linux in domains that were traditionally strongholds of Java and C++/C developers. Linux people developing with a Microsoft language? The simple “we won’t sue you” promise doesn’t explain it.

And then the penny dropped… Perhaps, Better the Devil You Know?

Read more…

Categories: Coding, Rants & Opinions Tags: , ,

C++ Closures

February 21, 2010 8 comments

The upcoming C++0x standard has already ratified the Lambda Expression concept, which is also being touted as closures. Kinda.

I’m not keen on the syntax, at all. It’s ugly. Even Herb Sutter fumbles with it. The whole thing feels hacky and grumble-grumble-give-them-something that lets you do it.

The problem with a closure is that you want to have your cake and eat it. You want to be able to pass around a pointer to a piece of code to execute, but then you probably want it to be stateful and packaged with a bunch of data.

You can use a struct/class with an operator() functor to implement this, and that’s OK as long as what you are passing the object pointer to knows that’s what you are doing.

But that is not very often the case, especially if you have to go through an API. Infact, function pointers are generally a PITA of C++ programmers.

Read more…

Categories: Coding Tags: ,
Follow

Get every new post delivered to your Inbox.

Join 216 other followers