-
Notifications
You must be signed in to change notification settings - Fork 456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
轻量aop 一个疑问 #44
Comments
把外层的也加上类似enable_if倒是能实现需求,但是感觉有点繁琐。加起来六个了。 template <typename T>
typename std::enable_if<has_member_Before<T, Args...>::value && has_member_After<T, Args...>::value>::type Invoke(Args&&... args, T&& aspect)
{
aspect.Before(std::forward<Args>(args)...); //核心逻辑之前的切面逻辑
m_func(std::forward<Args>(args)...); //核心逻辑
aspect.After(std::forward<Args>(args)...); //核心逻辑之后的切面逻辑
}
template <typename T>
typename std::enable_if<has_member_Before<T, Args...>::value && !has_member_After<T, Args...>::value>::type Invoke(Args&&... args, T&& aspect)
{
aspect.Before(std::forward<Args>(args)...); //核心逻辑之前的切面逻辑
m_func(std::forward<Args>(args)...); //核心逻辑
}
template <typename T>
typename std::enable_if<!has_member_Before<T, Args...>::value && has_member_After<T, Args...>::value>::type Invoke(Args&&... args, T&& aspect)
{
m_func(std::forward<Args>(args)...); //核心逻辑
aspect.After(std::forward<Args>(args)...); //核心逻辑之后的切面逻辑
}
template <typename Head, typename... Tail>
typename std::enable_if<has_member_Before<Head, Args...>::value && has_member_After<Head, Args...>::value>::type Invoke(Args&&... args, Head&& headAspect, Tail&&... tailAspect)
{
headAspect.Before(std::forward<Args>(args)...);
Invoke(std::forward<Args>(args)..., std::forward<Tail>(tailAspect)...);
headAspect.After(std::forward<Args>(args)...);
}
template <typename Head, typename... Tail>
typename std::enable_if<!has_member_Before<Head, Args...>::value && has_member_After<Head, Args...>::value>::type Invoke(Args&&... args, Head&& headAspect, Tail&&... tailAspect)
{
Invoke(std::forward<Args>(args)..., std::forward<Tail>(tailAspect)...);
headAspect.After(std::forward<Args>(args)...);
}
template <typename Head, typename... Tail>
typename std::enable_if<has_member_Before<Head, Args...>::value && !has_member_After<Head, Args...>::value>::type Invoke(Args&&... args, Head&& headAspect, Tail&&... tailAspect)
{
headAspect.Before(std::forward<Args>(args)...);
Invoke(std::forward<Args>(args)..., std::forward<Tail>(tailAspect)...);
}
|
我想说的是尽快升级到c++17以上,c++11已经是十多年前的标准了,有一些过时了。 |
up大大你好,请问C++17的跨平台性怎么样了,各个平台行为一致了吗? |
C++17 是iso 标准,各个平台都会遵循标准去实现,标准C++跨平台没有问题,另外现在都开始用C++20 了,如果能一步升级到C++20 更好。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
aop切面的递归展开只有最里层才允许没有Before或者After其中一个,外层全部都必须要Before和After
和博客里的设计初衷有偏差 https://www.cnblogs.com/qicosmos/p/4772389.html
The text was updated successfully, but these errors were encountered: