#ifndef MKF_FIFOLIST_HPP_INCLUDED
#define MKF_FIFOLIST_HPP_INCLUDED


#include<cstddef>


template<typename  T>
class
fifolist
{
  struct Entry{
    T  data;

    Entry*  next;

    Entry(const T&   t): data(          t ), next(nullptr){}
    Entry(      T&&  t): data(std::move(t)), next(nullptr){}

  };


  Entry*  first;
  Entry*   last;

  void  push(Entry*  ent)
  {
      if(last)
      {
        last->next = ent;
        last       = ent;
      }

    else
      {
        first = ent;
        last  = ent;
      }
  }

public:
  fifolist(): first(nullptr), last(nullptr){}
 ~fifolist(){clear();}

  void  clear()
  {
      while(first)
      {
        auto  next = first->next;

        first->data.~T();

        delete first       ;
               first = next;
      }


    last = nullptr;
  }

  void  push(const T&  t)
  {
    push(new Entry(t));
  }

  void  push(T&&  t)
  {
    push(new Entry(std::move(t)));
  }

  void  pop()
  {
      if(first == last)
      {
        first->data.~T();

        delete first;

        first = nullptr;
         last = nullptr;
      }

    else
      {
        auto  next = first->next;

        first->data.~T();

        delete first       ;
               first = next;
      }
  }


  const Entry*  get_first() const{return first;}
  const Entry*  get_last()  const{return  last;}

};




#endif




