C++ assert语句内模板结构实例化的语法错误

C++ assert语句内模板结构实例化的语法错误,c++,templates,syntax-error,C++,Templates,Syntax Error,对于在标头中定义的以下模板结构: #include <unordered_set> namespace Utilities::ContainerHelpers { template <template <class> class TContainer, class TVal> struct is_unique { bool operator()(TContainer<TVal> const& con

对于在标头中定义的以下模板结构:

#include <unordered_set>

namespace Utilities::ContainerHelpers
{
    template <template <class> class TContainer, class TVal>
    struct is_unique
    {
        bool operator()(TContainer<TVal> const& container) const
        {
            std::unordered_set<TVal, typename TVal::HashFunc> 
                uniqueSubset(container.begin(), container.end());

            return container.size() == uniqueSubset.size();
        }
    };
}
#包括
命名空间实用程序::ContainerHelpers
{
模板
结构是唯一的
{
布尔运算符()(t容器常量和容器)常量
{
std::无序_集
唯一子集(container.begin(),container.end());
返回container.size()==uniqueSubset.size();
}
};
}
在断言上下文中使用时,出现语法错误:

assert(Utilities::ContainerHelpers::is_unique< std::vector, TelemDetail >{}(telem_detail_obj);
assert(Utilities::ContainerHelpers::is_unique{}(telem_detail_obj);
但当定义为断言外部的临时类型时,则不是。类型
telemail
不重要,只包含嵌套的
HashFunc
struct类型

警告C4002:宏调用“assert”等函数的参数太多

错误C2059:语法错误:')'


感觉我错过了一些明显的东西?用MSVC 2019—STD= C++ 17

< P> <代码> AsSturi> <代码>,作为每个宏,不理解C++,它将每个逗号<代码>,<代码>作为参数分隔符:

assert(is_unique< std::vector, TelemDetail >{}(session_details));
//    (   first arg          ,  second arg                     )
//                                   
assert(是唯一的{}(会话详细信息));
//(第一个参数,第二个参数)
//                                   
但是预处理器宏“理解”
()
——所以只需添加额外的一对
()


assert((是唯一的{}(会话详细信息))

在上编译。因此,缺少一些信息。如果我将assert参数包装在另一组括号中,似乎会起作用,但我不知道为什么?如果您想让其他人知道原因,您需要显示一个。@M.a您没有抓住要点。您应该发布尽可能接近问题的代码。我们不应该有问题重复这个问题。无论如何,PiotrNycz能够填补空白并提供了一个答案。还可以做一个改进:在args中使用variadic:
模板类TContainer
-例如std::vector有两个arg-而不仅仅是一个(第二个默认为
std::allocator
)“逗号”,而不是“冒号”