#include <iostream>

/*
http://en.wikipedia.org/wiki/Functional_programming
http://en.wikipedia.org/wiki/Function_object
http://www.johndcook.com/blog/2008/12/19/functional-programming-in-c-with-function-objects/
http://www.cplusplus.com/reference/std/functional/
*/

struct not_null
{
  bool operator () (char * src, int index)
  {
    return *(src+index) != 0;
  }
}is_not_null;

struct same_as
{
  bool operator () (char * src, char letter, int index = 0)
  {
    return *(src+index) == letter;
  }
}the_same_as;

struct size_of
{
  int operator () (char * src, int start=0)
  {
    int index = 0;
    while (is_not_null(src,index+start))
    {
      index++ ;
    }
    return index;
  }
}the_size_of;

struct index_of
{
  int operator () (char * src, char letter, int index=0)
  {
    while (is_not_null(src,index))
    {
      if (the_same_as(src,letter,index))
      {
        return index;
      }
      index++ ;
    }
    return index;
  }
}the_index_of;

struct last_index_of
{
  int operator () (char * src, char letter, int start=0)
  {
    int index = the_size_of(src)-1;
    while (index > start)
    {
      if (the_same_as(src,letter,index))
      {
        return index;
      }
      index-- ;
    }
    return index;
  }
}the_last_index_of;

struct part_of
{
  char * operator () (char * src, int start, int end)
  {
    char * the_part = new char[end-start];
    int index = 0;
    while (is_not_null(src,start+index)&& (start+index<end))
    {
      *(the_part+index) = *(src+start+index);
    }
    return the_part;  //dangerous one
  }
}a_part_of;

int main()
{
  char * test = "abcdefghijklm";
  std::cout << test << "\n";
  
  
  std::cout << the_size_of(test);
  
  std::cout << "\n";
  return 0;
}
