Question: In C# its possibly to use [AsDynamic](http://blogs.msdn.com/b/davidebb/archive/2010/01/18/use-c-4-0-dynamic-to-drastically-simplify-your-private-reflection-code.aspx) to invoke a overloaded method on a subclass (example [here](https://github.com/gregoryyoung/m-r/blob/master/SimpleCQRS/Domain.cs)) thus allowing an abstract class to invoke methods it does not itself define. Is something similar possible with Scala 2.9 **applyDynamic** ?. I tried the following

```
abstract class AggregateRoot extends Dynamic {
  def applyChange(event: Event) {
    this.applyDynamic("handleEvent")(event) 
  }
  // this does not work
  def applyDynamic(name : String)(args: Any*) = this
}

```

used like this 

```
class InventoryItem extends AggregateRoot {
  def handleEvent(event: InventoryItemCreated) {
    println("received InventoryItemCreated")
  }

  def handleEvent(event: InventoryItemDeactivated) {
    println("received InventoryItemDeactivated")
  }
}

```

where **InventoryItemCreated** and **InventoryItemDeactivated** both are events

```
class Event;

class InventoryItemDeactivated extends Event; 

class InventoryItemCreated extends Event; 

```

I then expect to be able to do something like this

```
  var aggregate : AggregateRoot = new InventoryItem
  var event = new InventoryItemDeactivated
  aggregate.applyChange(event) // should print "received InventoryItemDeactivated"

```

but I cannot figure out how to define **applyDynamic** (in **AggregateRoot**) so that it can invoke overloaded methods in subclasses at runtime without itself defining them. Other solutions that achieve the same result are welcome (perhaps structural typing can come in handy ?).

Answer: 
The standard way to find the first list element whose value is the empty string is to use `std::find`:

```
std::list<std::string>::iterator it = std::find(whichList.begin(), whichlist.end(), "");

```

Its position can be computed (expensively) as `std::distance(whichList.begin(), it)`, but it is unlikely that you will need the actual numerical index, assuming that you have made a concious decision that `std::list` was the correct container type for your application.
I think you should use a vector for this problem.