Skip to content

Commit 32210f3

Browse files
committed
Vutils
1 parent 1904652 commit 32210f3

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

include/Vutils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3339,7 +3339,9 @@ class ThreadPool
33393339
// C++14 (MSVC 2015+ or MinGW 5.1+)
33403340
#if (defined(_MSC_VER) && _MSVC_LANG >= 201402L) || (defined(__MINGW32__) && __cplusplus >= 201402L)
33413341
#include "template/handle.tpl"
3342-
ScopedHandleT_Define(HANDLE, HANDLE, INVALID_HANDLE_VALUE, { CloseHandle(h); });
3342+
#ifndef __MINGW32__ // `error: 'reinterpret_cast' from integer to pointer`
3343+
ScopedHandleT_Define(HANDLE, HANDLE, HANDLE(INVALID_HANDLE_VALUE), { CloseHandle(h); });
3344+
#endif // __MINGW32__
33433345
ScopedHandleT_Define(NULL_HANDLE, HANDLE, nullptr, { CloseHandle(h); });
33443346
ScopedHandleT_Define(FILE, FILE*, nullptr, { fclose(h); });
33453347
#endif // C++14 (MSVC 2015+ or MinGW 5.1+)

include/template/misc.tpl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
// C++14 (MSVC 2015+ or MinGW 5.1+)
1010
#if (defined(_MSC_VER) && _MSVC_LANG >= 201402L) || (defined(__MINGW32__) && __cplusplus >= 201402L)
1111

12+
#include <sstream>
1213
#include <iostream>
1314

15+
/**
16+
* print(...) (Python like)
17+
*/
18+
1419
static void print_A()
1520
{
1621
std::cout << std::endl;
@@ -43,6 +48,42 @@ void print_W(Head&& head, Tail&&... tail)
4348
#define print print_A
4449
#endif
4550

51+
/**
52+
* _cout(....) // push all items into string-stream then use `std::cout` out to STDOUT with-in a single out
53+
*/
54+
55+
template<typename Stream>
56+
void __vu_cout_impl(Stream& stream) {}
57+
58+
template<typename Stream, typename T, typename... Args>
59+
void __vu_cout_impl(Stream& stream, T&& t, Args&&... args)
60+
{
61+
stream << std::forward<T>(t);
62+
__vu_cout_impl(stream, std::forward<Args>(args)...);
63+
}
64+
65+
template<typename... Args>
66+
void _cout_A(Args&&... args)
67+
{
68+
std::stringstream ss;
69+
__vu_cout_impl(ss, std::forward<Args>(args)...);
70+
std::cout << ss.str();
71+
}
72+
73+
template<typename... Args>
74+
void _cout_W(Args&&... args)
75+
{
76+
std::wstringstream ss;
77+
__vu_cout_impl(ss, std::forward<Args>(args)...);
78+
std::wcout << ss.str();
79+
}
80+
81+
#ifdef _UNICODE
82+
#define _cout _cout_W
83+
#else
84+
#define _cout _cout_A
85+
#endif
86+
4687
#define VU_HAS_PRINT
4788

4889
#endif

0 commit comments

Comments
 (0)