Skip to content

Commit

Permalink
Vutils
Browse files Browse the repository at this point in the history
  • Loading branch information
vic4key committed Nov 14, 2023
1 parent 1904652 commit 32210f3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/Vutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3339,7 +3339,9 @@ class ThreadPool
// C++14 (MSVC 2015+ or MinGW 5.1+)
#if (defined(_MSC_VER) && _MSVC_LANG >= 201402L) || (defined(__MINGW32__) && __cplusplus >= 201402L)
#include "template/handle.tpl"
ScopedHandleT_Define(HANDLE, HANDLE, INVALID_HANDLE_VALUE, { CloseHandle(h); });
#ifndef __MINGW32__ // `error: 'reinterpret_cast' from integer to pointer`
ScopedHandleT_Define(HANDLE, HANDLE, HANDLE(INVALID_HANDLE_VALUE), { CloseHandle(h); });
#endif // __MINGW32__
ScopedHandleT_Define(NULL_HANDLE, HANDLE, nullptr, { CloseHandle(h); });
ScopedHandleT_Define(FILE, FILE*, nullptr, { fclose(h); });
#endif // C++14 (MSVC 2015+ or MinGW 5.1+)
Expand Down
41 changes: 41 additions & 0 deletions include/template/misc.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
// C++14 (MSVC 2015+ or MinGW 5.1+)
#if (defined(_MSC_VER) && _MSVC_LANG >= 201402L) || (defined(__MINGW32__) && __cplusplus >= 201402L)

#include <sstream>
#include <iostream>

/**
* print(...) (Python like)
*/

static void print_A()
{
std::cout << std::endl;
Expand Down Expand Up @@ -43,6 +48,42 @@ void print_W(Head&& head, Tail&&... tail)
#define print print_A
#endif

/**
* _cout(....) // push all items into string-stream then use `std::cout` out to STDOUT with-in a single out
*/

template<typename Stream>
void __vu_cout_impl(Stream& stream) {}

template<typename Stream, typename T, typename... Args>
void __vu_cout_impl(Stream& stream, T&& t, Args&&... args)
{
stream << std::forward<T>(t);
__vu_cout_impl(stream, std::forward<Args>(args)...);
}

template<typename... Args>
void _cout_A(Args&&... args)
{
std::stringstream ss;
__vu_cout_impl(ss, std::forward<Args>(args)...);
std::cout << ss.str();
}

template<typename... Args>
void _cout_W(Args&&... args)
{
std::wstringstream ss;
__vu_cout_impl(ss, std::forward<Args>(args)...);
std::wcout << ss.str();
}

#ifdef _UNICODE
#define _cout _cout_W
#else
#define _cout _cout_A
#endif

#define VU_HAS_PRINT

#endif

0 comments on commit 32210f3

Please sign in to comment.