Tech Tips
edited by George Frazier


A Null Iterator Type for STL
by Dan Shappir

Listing One

class null_iterator
#if defined(_MSC_VER) && _MSC_VER < 1300
      : public std::iterator
#else
      : public std::iterator
#endif
{
public:
      typedef void container_type;
private:
      class proxy
      {
      public:
            template
                  proxy& operator=(const _Ty&)
            { return *this; }
      };
public:
      proxy operator*()
            { return proxy(); }
      null_iterator& operator++()
            { return *this; }
      null_iterator operator++(int)
            { return *this; }
      bool operator==(const null_iterator&) const
            { return true; }
      bool operator!=(const null_iterator&) const
            { return false; }
};




Enumerating Registry Sub-keys in D
by Matthew Wilson

Listing Two

private LONG _Reg_EnumKeyName(  in    HKEY    hkey
                              , in    DWORD   index
                              , inout char[]  name
                              , out   DWORD   cchName)
in
{
  assert(null !== hkey);
  assert(null !== name);
  assert(0 < name.length);
}
body
{
  LONG    res;

  for(;;)
  {
      cchName = name.length;

      res = RegEnumKeyExA(hkey, index, name
              , cchName, RESERVED, null, null, null);

      if(ERROR_MORE_DATA != res)
      {
          break;
      }
      else
      {
          // Increase the size of the buffer and try again
          name.length = 2 * name.length;
      }
  }

  return res;
}




