#pragma once
#include <cstdint>
#include <chrono>
#if defined(_WIN32)
#include <Windows.h>
#elif defined(__unix__)
#include <time.h>
#else
#error dasdasd
#endif
struct win_time
{
using rep = int64_t;
using period = std::ratio<1, 10000000>;
using duration = std::chrono::duration<rep, period>;
using time_point = std::chrono::time_point<win_time, duration>;
static time_point now() noexcept;
static constexpr bool is_steady = true;
private:
static constexpr int64_t UNIX_START = 116444736000000000;
};
inline win_time::time_point win_time::now() noexcept
{
#if defined(_WIN32)
FILETIME ft;
GetSystemTimePreciseAsFileTime( &ft );
return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 | ft.dwLowDateTime ) );
#elif defined(__unix__)
timespec ts;
clock_gettime( CLOCK_REALTIME, &ts );
return time_point( duration( UNIX_START + (uint64_t)ts.tv_sec * 10'000'000u + ((uint64_t)ts.tv_nsec + 50u) / 100u ) );
#endif
}
What does this do ?
Oh, wrong group.
Am 07.09.2025 um 18:57 schrieb Bonita Montero:
#pragma once
#include <cstdint>
#include <chrono>
#if defined(_WIN32)
#include <Windows.h>
#elif defined(__unix__)
#include <time.h>
#else
#error dasdasd
#endif
struct win_time
{
using rep = int64_t;
using period = std::ratio<1, 10000000>;
using duration = std::chrono::duration<rep, period>;
using time_point = std::chrono::time_point<win_time, duration>; static time_point now() noexcept;
static constexpr bool is_steady = true;
private:
static constexpr int64_t UNIX_START = 116444736000000000;
};
inline win_time::time_point win_time::now() noexcept
{
#if defined(_WIN32)
FILETIME ft;
GetSystemTimePreciseAsFileTime( &ft );
return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 | ft.dwLowDateTime ) );
#elif defined(__unix__)
timespec ts;
clock_gettime( CLOCK_REALTIME, &ts );
return time_point( duration( UNIX_START + (uint64_t)ts.tv_sec * 10'000'000u + ((uint64_t)ts.tv_nsec + 50u) / 100u ) );
#endif
}
What does this do ?
#pragma once
#include <cstdint>
#include <chrono>
#if defined(_WIN32)
#include <Windows.h>
#elif defined(__unix__)
#include <time.h>
#else
#error dasdasd
#endif
struct win_time
{
using rep = int64_t;
using period = std::ratio<1, 10000000>;
using duration = std::chrono::duration<rep, period>;
using time_point = std::chrono::time_point<win_time, duration>;
static time_point now() noexcept;
static constexpr bool is_steady = false;
private:
static constexpr time_point UNIX_START = time_point( duration( 116444736000000000 ) );
};
inline win_time::time_point win_time::now() noexcept
{
#if defined(_WIN32)
FILETIME ft;
GetSystemTimePreciseAsFileTime( &ft );
return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 | ft.dwLowDateTime ) );
#elif defined(__unix__)
using namespace std::chrono;
timespec ts;
clock_gettime( CLOCK_REALTIME, &ts );
return UNIX_START + duration_cast<win_time::duration>( seconds( ts.tv_sec ) + nanoseconds( ts.tv_nsec + 50 ) );
#endif
}
On Sun, 2025-09-07 at 19:28 +0200, Bonita Montero wrote:
Oh, wrong group.
Am 07.09.2025 um 18:57 schrieb Bonita Montero:
#pragma once
#include <cstdint>
#include <chrono>
#if defined(_WIN32)
#include <Windows.h>
#elif defined(__unix__)
#include <time.h>
#else
#error dasdasd
#endif
struct win_time
{
using rep = int64_t;
using period = std::ratio<1, 10000000>;
using duration = std::chrono::duration<rep, period>;
using time_point = std::chrono::time_point<win_time, duration>; >>> static time_point now() noexcept;
static constexpr bool is_steady = true;
private:
static constexpr int64_t UNIX_START = 116444736000000000;
};
inline win_time::time_point win_time::now() noexcept
{
#if defined(_WIN32)
FILETIME ft;
GetSystemTimePreciseAsFileTime( &ft );
return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 | >>> ft.dwLowDateTime ) );
#elif defined(__unix__)
timespec ts;
clock_gettime( CLOCK_REALTIME, &ts );
return time_point( duration( UNIX_START + (uint64_t)ts.tv_sec * >>> 10'000'000u + ((uint64_t)ts.tv_nsec + 50u) / 100u ) );
#endif
}
What does this do ?
#pragma once
#include <cstdint>
#include <chrono>
#if defined(_WIN32)
#include <Windows.h>
#elif defined(__unix__)
#include <time.h>
#else
#error dasdasd
#endif
struct win_time
{
using rep = int64_t;
using period = std::ratio<1, 10000000>;
using duration = std::chrono::duration<rep, period>;
using time_point = std::chrono::time_point<win_time, duration>;
static time_point now() noexcept;
static constexpr bool is_steady = false;
private:
static constexpr time_point UNIX_START = time_point( duration(
116444736000000000 ) );
};
inline win_time::time_point win_time::now() noexcept
{
#if defined(_WIN32)
FILETIME ft;
GetSystemTimePreciseAsFileTime( &ft );
return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 |
ft.dwLowDateTime ) );
#elif defined(__unix__)
using namespace std::chrono;
timespec ts;
clock_gettime( CLOCK_REALTIME, &ts );
return UNIX_START + duration_cast<win_time::duration>( seconds(
ts.tv_sec ) + nanoseconds( ts.tv_nsec + 50 ) );
#endif
}
Typical problems of C++ program are demonstrated.
But first, what the purpose of win_time?
Am 07.09.2025 um 23:04 schrieb wij:
On Sun, 2025-09-07 at 19:28 +0200, Bonita Montero wrote:
Oh, wrong group.
Am 07.09.2025 um 18:57 schrieb Bonita Montero:
#pragma once
#include <cstdint>
#include <chrono>
#if defined(_WIN32)
#include <Windows.h>
#elif defined(__unix__)
#include <time.h>
#else
#error dasdasd
#endif
struct win_time
{
using rep = int64_t;
using period = std::ratio<1, 10000000>;
using duration = std::chrono::duration<rep, period>; using time_point = std::chrono::time_point<win_time, duration>;
static time_point now() noexcept;
static constexpr bool is_steady = true;
private:
static constexpr int64_t UNIX_START = 116444736000000000;
};
inline win_time::time_point win_time::now() noexcept
{
#if defined(_WIN32)
FILETIME ft;
GetSystemTimePreciseAsFileTime( &ft );
return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 |
ft.dwLowDateTime ) );
#elif defined(__unix__)
timespec ts;
clock_gettime( CLOCK_REALTIME, &ts );
return time_point( duration( UNIX_START + (uint64_t)ts.tv_sec *
10'000'000u + ((uint64_t)ts.tv_nsec + 50u) / 100u ) );
#endif
}
What does this do ?
#pragma once
#include <cstdint>
#include <chrono>
#if defined(_WIN32)
#include <Windows.h>
#elif defined(__unix__)
#include <time.h>
#else
#error dasdasd
#endif
struct win_time
{
using rep = int64_t;
using period = std::ratio<1, 10000000>;
using duration = std::chrono::duration<rep, period>;
using time_point = std::chrono::time_point<win_time, duration>;
static time_point now() noexcept;
static constexpr bool is_steady = false;
private:
static constexpr time_point UNIX_START = time_point( duration( 116444736000000000 ) );
};
inline win_time::time_point win_time::now() noexcept
{
#if defined(_WIN32)
FILETIME ft;
GetSystemTimePreciseAsFileTime( &ft );
return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 | ft.dwLowDateTime ) );
#elif defined(__unix__)
using namespace std::chrono;
timespec ts;
clock_gettime( CLOCK_REALTIME, &ts );
return UNIX_START + duration_cast<win_time::duration>( seconds( ts.tv_sec ) + nanoseconds( ts.tv_nsec + 50 ) );
#endif
}
Typical problems of C++ program are demonstrated.
But first, what the purpose of win_time?
Problems with auch a few lines of code - idiot !
On Sun, 2025-09-07 at 23:22 +0200, Bonita Montero wrote:
Am 07.09.2025 um 23:04 schrieb wij:
On Sun, 2025-09-07 at 19:28 +0200, Bonita Montero wrote:
Oh, wrong group.
Am 07.09.2025 um 18:57 schrieb Bonita Montero:
#pragma once
#include <cstdint>
#include <chrono>
#if defined(_WIN32)
#include <Windows.h>
#elif defined(__unix__)
#include <time.h>
#else
#error dasdasd
#endif
struct win_time
{
using rep = int64_t;
using period = std::ratio<1, 10000000>;
using duration = std::chrono::duration<rep, period>;
using time_point = std::chrono::time_point<win_time, duration>;
static time_point now() noexcept;
static constexpr bool is_steady = true;
private:
static constexpr int64_t UNIX_START = 116444736000000000; >>>>> };
inline win_time::time_point win_time::now() noexcept
{
#if defined(_WIN32)
FILETIME ft;
GetSystemTimePreciseAsFileTime( &ft );
return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 |
ft.dwLowDateTime ) );
#elif defined(__unix__)
timespec ts;
clock_gettime( CLOCK_REALTIME, &ts );
return time_point( duration( UNIX_START + (uint64_t)ts.tv_sec *
10'000'000u + ((uint64_t)ts.tv_nsec + 50u) / 100u ) );
#endif
}
What does this do ?
#pragma once
#include <cstdint>
#include <chrono>
#if defined(_WIN32)
#include <Windows.h>
#elif defined(__unix__)
#include <time.h>
#else
#error dasdasd
#endif
struct win_time
{
using rep = int64_t;
using period = std::ratio<1, 10000000>;
using duration = std::chrono::duration<rep, period>;
using time_point = std::chrono::time_point<win_time, duration>;
static time_point now() noexcept;
static constexpr bool is_steady = false;
private:
static constexpr time_point UNIX_START = time_point( duration(
116444736000000000 ) );
};
inline win_time::time_point win_time::now() noexcept
{
#if defined(_WIN32)
FILETIME ft;
GetSystemTimePreciseAsFileTime( &ft );
return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 |
ft.dwLowDateTime ) );
#elif defined(__unix__)
using namespace std::chrono;
timespec ts;
clock_gettime( CLOCK_REALTIME, &ts );
return UNIX_START + duration_cast<win_time::duration>( seconds(
ts.tv_sec ) + nanoseconds( ts.tv_nsec + 50 ) );
#endif
}
Typical problems of C++ program are demonstrated.
But first, what the purpose of win_time?
Problems with auch a few lines of code - idiot !
You simplified the problem you were dealing with, not really the programming.
Also, from my always-check-errors policy, you missed the checking for errors and 'noexcept' of now() is problematic.
Am 08.09.2025 um 13:46 schrieb wij:
On Sun, 2025-09-07 at 23:22 +0200, Bonita Montero wrote:
Am 07.09.2025 um 23:04 schrieb wij:
On Sun, 2025-09-07 at 19:28 +0200, Bonita Montero wrote:
Oh, wrong group.
Am 07.09.2025 um 18:57 schrieb Bonita Montero:
#pragma once
#include <cstdint>
#include <chrono>
#if defined(_WIN32)
#include <Windows.h>
#elif defined(__unix__)
#include <time.h>
#else
#error dasdasd
#endif
struct win_time
{
using rep = int64_t;
using period = std::ratio<1, 10000000>;
using duration = std::chrono::duration<rep, period>; using time_point = std::chrono::time_point<win_time, duration>;
static time_point now() noexcept;
static constexpr bool is_steady = true;
private:
static constexpr int64_t UNIX_START = 116444736000000000;
};
inline win_time::time_point win_time::now() noexcept
{
#if defined(_WIN32)
FILETIME ft;
GetSystemTimePreciseAsFileTime( &ft );
return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 |
ft.dwLowDateTime ) );
#elif defined(__unix__)
timespec ts;
clock_gettime( CLOCK_REALTIME, &ts );
return time_point( duration( UNIX_START + (uint64_t)ts.tv_sec *
10'000'000u + ((uint64_t)ts.tv_nsec + 50u) / 100u ) );
#endif
}
What does this do ?
#pragma once
#include <cstdint>
#include <chrono>
#if defined(_WIN32)
#include <Windows.h>
#elif defined(__unix__)
#include <time.h>
#else
#error dasdasd
#endif
struct win_time
{
using rep = int64_t;
using period = std::ratio<1, 10000000>;
using duration = std::chrono::duration<rep, period>;
using time_point = std::chrono::time_point<win_time, duration>;
static time_point now() noexcept;
static constexpr bool is_steady = false;
private:
static constexpr time_point UNIX_START = time_point( duration( 116444736000000000 ) );
};
inline win_time::time_point win_time::now() noexcept
{
#if defined(_WIN32)
FILETIME ft;
GetSystemTimePreciseAsFileTime( &ft );
return time_point( duration( (uint64_t)ft.dwHighDateTime << 32 |
ft.dwLowDateTime ) );
#elif defined(__unix__)
using namespace std::chrono;
timespec ts;
clock_gettime( CLOCK_REALTIME, &ts );
return UNIX_START + duration_cast<win_time::duration>( seconds( ts.tv_sec ) + nanoseconds( ts.tv_nsec + 50 ) );
#endif
}
Typical problems of C++ program are demonstrated.
But first, what the purpose of win_time?
Problems with auch a few lines of code - idiot !
You simplified the problem you were dealing with, not really the programming.
Also, from my always-check-errors policy, you missed the checking for errors
and 'noexcept' of now() is problematic.
::now() is noexcept with C++ in general. So if C++ itself isn't dealing
with errors fot that actually never fails. AnGetSystemTimePreciseAs FileTime() has no error code at all.
I won't say too much.
Your implement contains possible abnormal termination.
Sysop: | Tetrazocine |
---|---|
Location: | Melbourne, VIC, Australia |
Users: | 14 |
Nodes: | 8 (0 / 8) |
Uptime: | 187:31:40 |
Calls: | 178 |
Files: | 21,502 |
Messages: | 79,847 |