code:
#ifndef BOOST_PROPERTY_TREE_DETAIL_JSON_PARSER_WIDE_ENCODING_HPP
#define BOOST_PROPERTY_TREE_DETAIL_JSON_PARSER_WIDE_ENCODING_HPP

#include <boost/assert.hpp>
#include <boost/range/iterator_range_core.hpp>

#include <utility>

namespace boost { namespace property_tree {
    namespace json_parser { namespace detail
{

    struct external_wide_encoding
    {
        typedef wchar_t external_char;

        bool is_nl(wchar_t c) const { return c == L'\n'; }
        bool is_ws(wchar_t c) const {
            return c == L' ' || c == L'\t' || c == L'\n' || c == L'\r';
        }

        bool is_minus(wchar_t c) const { return c == L'-'; }
        bool is_plusminus(wchar_t c) const { return c == L'+' || c == L'-'; }
        bool is_dot(wchar_t c) const { return c == L'.'; }
        bool is_eE(wchar_t c) const { return c == L'e' || c == L'E'; }
        bool is_0(wchar_t c) const { return c == L'0'; }
        bool is_digit(wchar_t c) const { return c >= L'0' && c <= L'9'; }
        bool is_digit0(wchar_t c) const { return c >= L'1' && c <= L'9'; }

        bool is_quote(wchar_t c) const { return c == L'"'; }
        bool is_backslash(wchar_t c) const { return c == L'\\'; }
        bool is_slash(wchar_t c) const { return c == L'/'; }

        bool is_comma(wchar_t c) const { return c == L','; }
        bool is_open_bracket(wchar_t c) const { return c == L'['; }
        bool is_close_bracket(wchar_t c) const { return c == L']'; }
        bool is_colon(wchar_t c) const { return c == L':'; }
        bool is_open_brace(wchar_t c) const { return c == L'{'; }
        bool is_close_brace(wchar_t c) const { return c == L'}'; }

        bool is_a(wchar_t c) const { return c == L'a'; }
        bool is_b(wchar_t c) const { return c == L'b'; }
        bool is_e(wchar_t c) const { return c == L'e'; }
        bool is_f(wchar_t c) const { return c == L'f'; }
        bool is_l(wchar_t c) const { return c == L'l'; }
        bool is_n(wchar_t c) const { return c == L'n'; }
        bool is_r(wchar_t c) const { return c == L'r'; }
        bool is_s(wchar_t c) const { return c == L's'; }
        bool is_t(wchar_t c) const { return c == L't'; }
        bool is_u(wchar_t c) const { return c == L'u'; }

        int decode_hexdigit(wchar_t c) {
            if (c >= L'0' && c <= L'9') return c - L'0';
            if (c >= L'A' && c <= L'F') return c - L'A' + 10;
            if (c >= L'a' && c <= L'f') return c - L'a' + 10;
            return -1;
        }
    };

    template <bool B> struct is_utf16 {};

    class wide_wide_encoding : public external_wide_encoding
    {
        typedef is_utf16<sizeof(wchar_t) == 2> test_utf16;
    public:
        typedef wchar_t internal_char;

        template <typename Iterator>
        boost::iterator_range<Iterator>
        to_internal(Iterator first, Iterator last) const {
            return boost::make_iterator_range(first, last);
        }

        wchar_t to_internal_trivial(wchar_t c) const {
            BOOST_ASSERT(!is_surrogate_high(c) && !is_surrogate_low(c));
            return c;
        }

        template <typename Iterator, typename Sentinel,
                  typename EncodingErrorFn>
        void skip_codepoint(Iterator& cur, Sentinel end,
                            EncodingErrorFn error_fn) const {
            transcode_codepoint(cur, end, DoNothing(), error_fn);
        }

        template <typename Iterator, typename Sentinel, typename TranscodedFn,
                  typename EncodingErrorFn>
        void transcode_codepoint(Iterator& cur, Sentinel end,
                TranscodedFn transcoded_fn, EncodingErrorFn error_fn) const {
            return transcode_codepoint(cur, end, transcoded_fn, error_fn,
                                       test_utf16());
        }

        template <typename TranscodedFn>
        void feed_codepoint(unsigned codepoint,
                            TranscodedFn transcoded_fn) const {
            feed_codepoint(codepoint, transcoded_fn, test_utf16());
        }

        template <typename Iterator, typename Sentinel>
        void skip_introduction(Iterator& cur, Sentinel end) const {
            // Endianness is already decoded at this level.
            if (cur != end && *cur == 0xfeff) {
                ++cur;
            }
        }

    private:
        struct DoNothing {
            void operator ()(wchar_t) const {}
        };

        template <typename Iterator, typename Sentinel, typename TranscodedFn,
                  typename EncodingErrorFn>
        void transcode_codepoint(Iterator& cur, Sentinel,
                                 TranscodedFn transcoded_fn,
                                 EncodingErrorFn error_fn,
                                 is_utf16<false>) const {
            wchar_t c = *cur;
            if (c < 0x20) {
                error_fn();
            }
            transcoded_fn(c);
            ++cur;
        }
        template <typename Iterator, typename Sentinel, typename TranscodedFn,
                  typename EncodingErrorFn>
        void transcode_codepoint(Iterator& cur, Sentinel end,
                                 TranscodedFn transcoded_fn,
                                 EncodingErrorFn error_fn,
                                 is_utf16<true>) const {
            wchar_t c = *cur;
            if (c < 0x20) {
                error_fn();
            }
            if (is_surrogate_low(c)) {
                error_fn();
            }
            transcoded_fn(c);
            ++cur;
            if (is_surrogate_high(c)) {
                if (cur == end) {
                    error_fn();
                }
                c = *cur;
                if (!is_surrogate_low(c)) {
                    error_fn();
                }
                transcoded_fn(c);
                ++cur;
            }
        }

        template <typename TranscodedFn>
        void feed_codepoint(unsigned codepoint, TranscodedFn transcoded_fn,
                            is_utf16<false>) const {
            transcoded_fn(static_cast<wchar_t>(codepoint));
        }
        template <typename TranscodedFn>
        void feed_codepoint(unsigned codepoint, TranscodedFn transcoded_fn,
                            is_utf16<true>) const {
            if (codepoint < 0x10000) {
                transcoded_fn(static_cast<wchar_t>(codepoint));
            } else {
                codepoint -= 0x10000;
                transcoded_fn(static_cast<wchar_t>((codepoint >> 10) | 0xd800));
                transcoded_fn(static_cast<wchar_t>(
                    (codepoint & 0x3ff) | 0xdc00));
            }
        }

        static bool is_surrogate_high(unsigned codepoint) {
            return (codepoint & 0xfc00) == 0xd800;
        }
        static bool is_surrogate_low(unsigned codepoint) {
            return (codepoint & 0xfc00) == 0xdc00;
        }
    };

}}}}

#endif


code:
#include <windows.h>
#include <tlhelp32.h>
#include <iostream>

int killbyname(const char *szToTerminate)
// Created: 6/23/2000  (Ravi Kochhar)
// Last modified: 3/10/2002  (RK)
// Please report any problems or bugs to kochhar@physiology.wisc.edu
// The latest version of this routine can be found at:
//     http://www.neurophys.wisc.edu/ravi/software/killproc/
// Terminate the process "szToTerminate" if it is currently running
// This works for Win/95/98/ME and also Win/NT/2000/XP
// The process name is case-insensitive, i.e. "notepad.exe" and "NOTEPAD.EXE"
// will both work (for szToTerminate)
// Return codes are as follows:
//   0   = Process was successfully terminated
//   602 = Unable to terminate process for some other reason
//   603 = Process was not currently running
//   604 = No permission to terminate process
//   605 = Unable to load PSAPI.DLL
//   606 = Unable to identify system type
//   607 = Unsupported OS
//   632 = Invalid process name
//   700 = Unable to get procedure address from PSAPI.DLL
//   701 = Unable to get process list, EnumProcesses failed
//   702 = Unable to load KERNEL32.DLL
//   703 = Unable to get procedure address from KERNEL32.DLL
//   704 = CreateToolhelp32Snapshot failed

{
  BOOL bResult,bResultm;
  DWORD aiPID[1000],iCb=1000,iNumProc;  //,iV2000=0;
  DWORD iCbneeded,i,iFound=0;
  char szName[MAX_PATH],szToTermUpper[MAX_PATH];
  HANDLE hProc,hSnapShot,hSnapShotm;
  OSVERSIONINFO osvi;
  HINSTANCE hInstLib;
//  int iLen,iLenP,indx;
  int iLenP,indx;
  HMODULE hMod;
  PROCESSENTRY32 procentry;
  MODULEENTRY32 modentry;

  // Transfer Process name into "szToTermUpper" and convert to upper case
  iLenP=strlen(szToTerminate);
  if(iLenP<1 || iLenP>MAX_PATH) return 632;
  for(indx=0;indx<iLenP;indx++)
    szToTermUpper[indx]=toupper(szToTerminate[indx]);
  szToTermUpper[iLenP]=0;

  // PSAPI Function Pointers.
  BOOL (WINAPI *lpfEnumProcesses)( DWORD *, DWORD cb, DWORD * );
  BOOL (WINAPI *lpfEnumProcessModules)( HANDLE, HMODULE *,
                                        DWORD, LPDWORD );
  DWORD (WINAPI *lpfGetModuleBaseName)( HANDLE, HMODULE,
                                        LPTSTR, DWORD );

  // ToolHelp Function Pointers.
  HANDLE (WINAPI *lpfCreateToolhelp32Snapshot)(DWORD,DWORD) ;
  BOOL (WINAPI *lpfProcess32First)(HANDLE,LPPROCESSENTRY32) ;
  BOOL (WINAPI *lpfProcess32Next)(HANDLE,LPPROCESSENTRY32) ;
  BOOL (WINAPI *lpfModule32First)(HANDLE,LPMODULEENTRY32) ;
  BOOL (WINAPI *lpfModule32Next)(HANDLE,LPMODULEENTRY32) ;

  // First check what version of Windows we're in
  osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  bResult=GetVersionEx(&osvi);
  if(!bResult) return 606;    // Unable to identify system version

  // At Present we only support Win/NT/2000/XP or Win/9x/ME
  // Seems to work OK in Win7
  if((osvi.dwPlatformId != VER_PLATFORM_WIN32_NT) &&
     (osvi.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS)) return 607;

  if(osvi.dwPlatformId==VER_PLATFORM_WIN32_NT)
  {
    // Win/NT or 2000 or XP

    // Load library and get the procedures explicitly. We do
    // this so that we don't have to worry about modules using
    // this code failing to load under Windows 9x, because
    // it can't resolve references to the PSAPI.DLL.
    hInstLib = LoadLibraryA("PSAPI.DLL");
    if(hInstLib == NULL) return 605;

    // Get procedure addresses.
    lpfEnumProcesses = (BOOL(WINAPI *)(DWORD *,DWORD,DWORD*))
        GetProcAddress( hInstLib, "EnumProcesses" ) ;
    lpfEnumProcessModules = (BOOL(WINAPI *)(HANDLE, HMODULE *,
        DWORD, LPDWORD)) GetProcAddress( hInstLib,                                                                     "EnumProcessModules" ) ;
        lpfGetModuleBaseName =(DWORD (WINAPI *)(HANDLE, HMODULE, LPTSTR,
        DWORD )) GetProcAddress( hInstLib, "GetModuleBaseNameA" ) ;

    if(lpfEnumProcesses == NULL || lpfEnumProcessModules == NULL ||
         lpfGetModuleBaseName == NULL) {
      FreeLibrary(hInstLib);
      return 700;
    }

    bResult=lpfEnumProcesses(aiPID,iCb,&iCbneeded);
    if(!bResult) {
      // Unable to get process list, EnumProcesses failed
      FreeLibrary(hInstLib);
      return 701;
    }

    // How many processes are there?
    iNumProc=iCbneeded/sizeof(DWORD);

    // Get and match the name of each process
    for(i=0;i<iNumProc;i++) {
      // Get the (module) name for this process
      strcpy(szName,"Unknown");
      // First, get a handle to the process
      hProc=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,FALSE,
                        aiPID[i]);
      // Now, get the process name
      if(hProc) {
        if(lpfEnumProcessModules(hProc,&hMod,sizeof(hMod),&iCbneeded) ) {
//          iLen=lpfGetModuleBaseName(hProc,hMod,szName,MAX_PATH);
          lpfGetModuleBaseName(hProc,hMod,szName,MAX_PATH);
        }
      }
      CloseHandle(hProc);
      // We will match regardless of lower or upper case
      if(strcmp(_strupr(szName),szToTermUpper)==0) {
        // Process found, now terminate it
        iFound=1;
        // First open for termination
        hProc=OpenProcess(PROCESS_TERMINATE,FALSE,aiPID[i]);
        if(hProc) {
          if(TerminateProcess(hProc,0)) {
            // process terminated
            CloseHandle(hProc);
            FreeLibrary(hInstLib);
            return 0;
          } else {
            // Unable to terminate process
            CloseHandle(hProc);
            FreeLibrary(hInstLib);
            return 602;
          }
        } else {
          // Unable to open process for termination
          FreeLibrary(hInstLib);
          return 604;
        }
      }
    }
  }

  if(osvi.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS)
  {
    // Win/95 or 98 or ME

    hInstLib = LoadLibraryA("Kernel32.DLL");
    if( hInstLib == NULL )
      return 702;

    // Get procedure addresses.
    // We are linking to these functions of Kernel32
    // explicitly, because otherwise a module using
    // this code would fail to load under Windows NT,
    // which does not have the Toolhelp32
    // functions in the Kernel 32.
    lpfCreateToolhelp32Snapshot=
        (HANDLE(WINAPI *)(DWORD,DWORD))
        GetProcAddress( hInstLib,
                        "CreateToolhelp32Snapshot" ) ;
    lpfProcess32First=
        (BOOL(WINAPI *)(HANDLE,LPPROCESSENTRY32))
        GetProcAddress( hInstLib, "Process32First" ) ;
    lpfProcess32Next=
        (BOOL(WINAPI *)(HANDLE,LPPROCESSENTRY32))
        GetProcAddress( hInstLib, "Process32Next" ) ;
    lpfModule32First=
        (BOOL(WINAPI *)(HANDLE,LPMODULEENTRY32))
        GetProcAddress( hInstLib, "Module32First" ) ;
    lpfModule32Next=
        (BOOL(WINAPI *)(HANDLE,LPMODULEENTRY32))
        GetProcAddress( hInstLib, "Module32Next" ) ;
    if( lpfProcess32Next == NULL ||
        lpfProcess32First == NULL ||
        lpfModule32Next == NULL ||
        lpfModule32First == NULL ||
        lpfCreateToolhelp32Snapshot == NULL )
    {
      FreeLibrary(hInstLib);
      return 703;
    }

    // The Process32.. and Module32.. routines return names in all uppercase

    // Get a handle to a Toolhelp snapshot of all the systems processes.

    hSnapShot = lpfCreateToolhelp32Snapshot(
          TH32CS_SNAPPROCESS, 0 ) ;
    if( hSnapShot == INVALID_HANDLE_VALUE )
    {
      FreeLibrary(hInstLib);
      return 704;
    }

    // Get the first process' information.
    procentry.dwSize = sizeof(PROCESSENTRY32);
    bResult=lpfProcess32First(hSnapShot,&procentry);

    // While there are processes, keep looping and checking.
    while(bResult)
    {
      // Get a handle to a Toolhelp snapshot of this process.
      hSnapShotm = lpfCreateToolhelp32Snapshot(
            TH32CS_SNAPMODULE, procentry.th32ProcessID) ;
      if( hSnapShotm == INVALID_HANDLE_VALUE )
      {
        CloseHandle(hSnapShot);
        FreeLibrary(hInstLib);
        return 704;
      }
      // Get the module list for this process
      modentry.dwSize=sizeof(MODULEENTRY32);
      bResultm=lpfModule32First(hSnapShotm,&modentry);

      // While there are modules, keep looping and checking
      while(bResultm)
      {
        if(strcmp(modentry.szModule,szToTermUpper)==0)
        {
          // Process found, now terminate it
          iFound=1;
          // First open for termination
          hProc=OpenProcess(PROCESS_TERMINATE,FALSE,procentry.th32ProcessID);
          if(hProc)
          {
            if(TerminateProcess(hProc,0))
            {
              // process terminated
              CloseHandle(hSnapShotm);
              CloseHandle(hSnapShot);
              CloseHandle(hProc);
              FreeLibrary(hInstLib);
              return 0;
            }
            else
            {
              // Unable to terminate process
              CloseHandle(hSnapShotm);
              CloseHandle(hSnapShot);
              CloseHandle(hProc);
              FreeLibrary(hInstLib);
              return 602;
            }
          }
          else
          {
            // Unable to open process for termination
            CloseHandle(hSnapShotm);
            CloseHandle(hSnapShot);
            FreeLibrary(hInstLib);
            return 604;
          }
        }
        else
        {  // Look for next modules for this process
          modentry.dwSize=sizeof(MODULEENTRY32);
          bResultm=lpfModule32Next(hSnapShotm,&modentry);
        }
      }

      //Keep looking
      CloseHandle(hSnapShotm);
      procentry.dwSize = sizeof(PROCESSENTRY32);
      bResult = lpfProcess32Next(hSnapShot,&procentry);
    }
    CloseHandle(hSnapShot);
  }
  if(iFound==0)
  {
    FreeLibrary(hInstLib);
    return 603;
  }
  FreeLibrary(hInstLib);
  return 0;
}

license: mit


code:
    ///////////////////////////////////////////////////////////////////////////////
    // template_arity_helper.hpp
    // Overloads of template_arity_helper, used by the template_arity\<\> class template
    //
    //  Copyright 2008 Eric Niebler. Distributed under the Boost
    //  Software License, Version 1.0. (See accompanying file
    //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
    template<
        template<typename P0> class F
      , typename T0
    >
    sized_type<2>::type
    template_arity_helper(F<T0> **, mpl::int_<1> *);
    template<
        template<typename P0 , typename P1> class F
      , typename T0 , typename T1
    >
    sized_type<3>::type
    template_arity_helper(F<T0 , T1> **, mpl::int_<2> *);
    template<
        template<typename P0 , typename P1 , typename P2> class F
      , typename T0 , typename T1 , typename T2
    >
    sized_type<4>::type
    template_arity_helper(F<T0 , T1 , T2> **, mpl::int_<3> *);
    template<
        template<typename P0 , typename P1 , typename P2 , typename P3> class F
      , typename T0 , typename T1 , typename T2 , typename T3
    >
    sized_type<5>::type
    template_arity_helper(F<T0 , T1 , T2 , T3> **, mpl::int_<4> *);
    template<
        template<typename P0 , typename P1 , typename P2 , typename P3 , typename P4> class F
      , typename T0 , typename T1 , typename T2 , typename T3 , typename T4
    >
    sized_type<6>::type
    template_arity_helper(F<T0 , T1 , T2 , T3 , T4> **, mpl::int_<5> *);
    template<
        template<typename P0 , typename P1 , typename P2 , typename P3 , typename P4 , typename P5> class F
      , typename T0 , typename T1 , typename T2 , typename T3 , typename T4 , typename T5
    >
    sized_type<7>::type
    template_arity_helper(F<T0 , T1 , T2 , T3 , T4 , T5> **, mpl::int_<6> *);
    template<
        template<typename P0 , typename P1 , typename P2 , typename P3 , typename P4 , typename P5 , typename P6> class F
      , typename T0 , typename T1 , typename T2 , typename T3 , typename T4 , typename T5 , typename T6
    >
    sized_type<8>::type
    template_arity_helper(F<T0 , T1 , T2 , T3 , T4 , T5 , T6> **, mpl::int_<7> *);
    template<
        template<typename P0 , typename P1 , typename P2 , typename P3 , typename P4 , typename P5 , typename P6 , typename P7> class F
      , typename T0 , typename T1 , typename T2 , typename T3 , typename T4 , typename T5 , typename T6 , typename T7
    >
    sized_type<9>::type
    template_arity_helper(F<T0 , T1 , T2 , T3 , T4 , T5 , T6 , T7> **, mpl::int_<8> *);
    template<
        template<typename P0 , typename P1 , typename P2 , typename P3 , typename P4 , typename P5 , typename P6 , typename P7 , typename P8> class F
      , typename T0 , typename T1 , typename T2 , typename T3 , typename T4 , typename T5 , typename T6 , typename T7 , typename T8
    >
    sized_type<10>::type
    template_arity_helper(F<T0 , T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8> **, mpl::int_<9> *);
    template<
        template<typename P0 , typename P1 , typename P2 , typename P3 , typename P4 , typename P5 , typename P6 , typename P7 , typename P8 , typename P9> class F
      , typename T0 , typename T1 , typename T2 , typename T3 , typename T4 , typename T5 , typename T6 , typename T7 , typename T8 , typename T9
    >
    sized_type<11>::type
    template_arity_helper(F<T0 , T1 , T2 , T3 , T4 , T5 , T6 , T7 , T8 , T9> **, mpl::int_<10> *);


code:
#ifndef INIT_RANDOM_SEED_H__
#define INIT_RANDOM_SEED_H__

#ifdef __cplusplus
extern "C" {
#endif

  /*
   * Generate a seed for the RANDOM_NUMBER PRNG that is guaranteed to
   * be unique even if many processes are started simultaneously
   *
   * Not suitable for multi-threaded requirements
   */
  void init_random_seed (void);

#ifdef __cplusplus
}
#endif

#endif