主要内容是更加规范的编译期行为与基于继承的Object反射

This commit is contained in:
2025-08-21 15:41:58 +08:00
parent 32e099b621
commit 004f2f3367
10 changed files with 1217 additions and 0 deletions

330
detail/CP/CWhile.hpp Normal file
View File

@@ -0,0 +1,330 @@
#pragma once
#ifndef __FILE_Detail_CP_CWhile_Hpp
#define __FILE_Detail_CP_CWhile_Hpp
struct CRange
{
template<template<int> class Callable, size_t End>
constexpr static void Range()
{
Range<Callable, 0, End>();
}
template<template<int> class Callable, int Start, int Stop, int Step = 1>
constexpr static void Range()
{
if constexpr (Step == 0)
static_assert(Step == 0, "Step not support 0");
Callable<Start> call;
call();
if constexpr (Start < Stop && Start + Step > Stop)
static_assert(Start < Stop && Start + Step > Stop, "While not stop");
if constexpr (Start > Stop && Start + Step < Stop)
static_assert(Start > Stop && Start + Step < Stop, "While not stop");
if constexpr (Start + Step != Stop)
Range<Callable, Start + Step, Stop, Step>();
}
};
template<typename... TemplateArgs>
struct CWhile
{
template<template<typename...> class Callable, template<typename...> class Pr, size_t MaxDepth, typename... Args>
constexpr static void WhileWithArgs(Args... args)
{
Callable<TemplateArgs...> call;
call(args...);
Pr<TemplateArgs...> pr;
if constexpr (pr(args...))
{
if constexpr (MaxDepth != 0)
{
WhileWithArgs<Callable, Pr, MaxDepth - 1, Args...>(args...);
}
else
{
static_assert(MaxDepth == 0, "WhileWithArgs is touch MaxDepth");
}
}
}
template<typename Callable, template<typename...> class Pr, size_t MaxDepth, typename... Args>
constexpr static void WhileWithArgs(Args... args)
{
Callable call;
call();
Pr<TemplateArgs...> pr;
if constexpr (pr(args...))
{
if constexpr (MaxDepth != 0)
{
WhileWithArgs<Callable, Pr, MaxDepth - 1, Args...>(args...);
}
else
{
static_assert(MaxDepth == 0, "WhileWithArgs is touch MaxDepth");
}
}
}
template<template<typename...> class Callable, typename Pr, size_t MaxDepth, typename... Args>
constexpr static void WhileWithArgs(Args... args)
{
Callable<TemplateArgs...> call;
call(args...);
Pr pr;
if constexpr (pr())
{
if constexpr (MaxDepth != 0)
{
WhileWithArgs<Callable, Pr, MaxDepth - 1, Args...>(args...);
}
else
{
static_assert(MaxDepth == 0, "WhileWithArgs is touch MaxDepth");
}
}
}
template<template<int, typename, typename...> class Callable, template<int, typename, typename...> class Pr, size_t MaxDepth, int Start, int Stop, int Step>
constexpr static void WhileWithTemplate()
{
Callable<Start, TemplateArgs...> call;
call();
Pr<Start, TemplateArgs...> pr;
if constexpr (pr())
{
if constexpr (MaxDepth != 0)
{
if constexpr (Start + Step != Stop)
WhileWithTemplate<Callable, Pr, MaxDepth - 1, Start + Step, Stop, Step>();
}
else
{
static_assert(MaxDepth == 0, "WhileWithTemplate is touch MaxDepth");
}
}
}
template<template<int> class Callable, template<int, typename, typename...> class Pr, size_t MaxDepth, int Start, int Stop, int Step>
constexpr static void WhileWithTemplate()
{
Callable<Start> call;
call();
Pr<Start, TemplateArgs...> pr;
if constexpr (pr())
{
if constexpr (MaxDepth != 0)
{
if constexpr (Start + Step != Stop)
WhileWithTemplate<Callable, Pr, MaxDepth - 1, Start + Step, Stop, Step>();
}
else
{
static_assert(MaxDepth == 0, "WhileWithTemplate is touch MaxDepth");
}
}
}
template<template<typename...> class Callable, template<int, typename, typename...> class Pr, size_t MaxDepth, int Start, int Stop, int Step>
constexpr static void WhileWithTemplate()
{
Callable<TemplateArgs...> call;
call();
Pr<Start, TemplateArgs...> pr;
if constexpr (pr())
{
if constexpr (MaxDepth != 0)
{
if constexpr (Start + Step != Stop)
WhileWithTemplate<Callable, Pr, MaxDepth - 1, Start + Step, Stop, Step>();
}
else
{
static_assert(MaxDepth == 0, "WhileWithTemplate is touch MaxDepth");
}
}
}
template<typename Callable, template<int, typename, typename...> class Pr, size_t MaxDepth, int Start, int Stop, int Step>
constexpr static void WhileWithTemplate()
{
Callable call;
call();
Pr<Start, TemplateArgs...> pr;
if constexpr (pr())
{
if constexpr (MaxDepth != 0)
{
if constexpr (Start + Step != Stop)
WhileWithTemplate<Callable, Pr, MaxDepth - 1, Start + Step, Stop, Step>();
}
else
{
static_assert(MaxDepth == 0, "WhileWithTemplate is touch MaxDepth");
}
}
}
template<template<int, typename, typename...> class Callable, template<int> class Pr, size_t MaxDepth, int Start, int Stop, int Step>
constexpr static void WhileWithTemplate()
{
Callable<Start, TemplateArgs...> call;
call();
Pr<Start> pr;
if constexpr (pr())
{
if constexpr (MaxDepth != 0)
{
if constexpr (Start + Step != Stop)
WhileWithTemplate<Callable, Pr, MaxDepth - 1, Start + Step, Stop, Step>();
}
else
{
static_assert(MaxDepth == 0, "WhileWithTemplate is touch MaxDepth");
}
}
}
template<template<int, typename, typename...> class Callable, template<typename...> class Pr, size_t MaxDepth, int Start, int Stop, int Step>
constexpr static void WhileWithTemplate()
{
Callable<Start, TemplateArgs...> call;
call();
Pr<TemplateArgs...> pr;
if constexpr (pr())
{
if constexpr (MaxDepth != 0)
{
if constexpr (Start + Step != Stop)
WhileWithTemplate<Callable, Pr, MaxDepth - 1, Start + Step, Stop, Step>();
}
else
{
static_assert(MaxDepth == 0, "WhileWithTemplate is touch MaxDepth");
}
}
}
template<template<int, typename, typename...> class Callable, typename Pr, size_t MaxDepth, int Start, int Stop, int Step>
constexpr static void WhileWithTemplate()
{
Callable<Start, TemplateArgs...> call;
call();
Pr pr;
if constexpr (pr())
{
if constexpr (MaxDepth != 0)
{
if constexpr (Start + Step != Stop)
WhileWithTemplate<Callable, Pr, MaxDepth - 1, Start + Step, Stop, Step>();
}
else
{
static_assert(MaxDepth == 0, "WhileWithTemplate is touch MaxDepth");
}
}
}
template<template<int> class Callable, template<int> class Pr, size_t MaxDepth, int Start, int Stop, int Step>
constexpr static void WhileWithTemplate()
{
Callable<Start> call;
call();
Pr<Start> pr;
if constexpr (pr())
{
if constexpr (MaxDepth != 0)
{
if constexpr (Start + Step != Stop)
WhileWithTemplate<Callable, Pr, MaxDepth - 1, Start + Step, Stop, Step>();
}
else
{
static_assert(MaxDepth == 0, "WhileWithTemplate is touch MaxDepth");
}
}
}
template<template<int> class Callable, template<typename...> class Pr, size_t MaxDepth, int Start, int Stop, int Step>
constexpr static void WhileWithTemplate()
{
Callable<Start> call;
call();
Pr<TemplateArgs...> pr;
if constexpr (pr())
{
if constexpr (MaxDepth != 0)
{
if constexpr (Start + Step != Stop)
WhileWithTemplate<Callable, Pr, MaxDepth - 1, Start + Step, Stop, Step>();
}
else
{
static_assert(MaxDepth == 0, "WhileWithTemplate is touch MaxDepth");
}
}
}
template<template<int> class Callable, typename Pr, size_t MaxDepth, int Start, int Stop, int Step>
constexpr static void WhileWithTemplate()
{
Callable<Start> call;
call();
Pr pr;
if constexpr (pr())
{
if constexpr (MaxDepth != 0)
{
if constexpr (Start + Step != Stop)
WhileWithTemplate<Callable, Pr, MaxDepth - 1, Start + Step, Stop, Step>();
}
else
{
static_assert(MaxDepth == 0, "WhileWithTemplate is touch MaxDepth");
}
}
}
template<template<typename...> class Callable, template<int> class Pr, size_t MaxDepth, int Start, int Stop, int Step>
constexpr static void WhileWithTemplate()
{
Callable<TemplateArgs...> call;
call();
Pr<Start> pr;
if constexpr (pr())
{
if constexpr (MaxDepth != 0)
{
if constexpr (Start + Step != Stop)
WhileWithTemplate<Callable, Pr, MaxDepth - 1, Start + Step, Stop, Step>();
}
else
{
static_assert(MaxDepth == 0, "WhileWithTemplate is touch MaxDepth");
}
}
}
template<template<typename...> class Callable, typename Pr, size_t MaxDepth, int Start, int Stop, int Step>
constexpr static void WhileWithTemplate()
{
Callable<TemplateArgs...> call;
call();
Pr pr;
if constexpr (pr())
{
if constexpr (MaxDepth != 0)
{
if constexpr (Start + Step != Stop)
WhileWithTemplate<Callable, Pr, MaxDepth - 1, Start + Step, Stop, Step>();
}
else
{
static_assert(MaxDepth == 0, "WhileWithTemplate is touch MaxDepth");
}
}
}
};
#endif // !__FILE_Detail_CP_CWhile_Hpp