[英]How can I use my custom enable_if in c++98?
I am currently making custom Vector container for the purpose of studying.我目前正在制作自定义 Vector 容器以用于学习。 My assignment has limitation that i should use c++98 version.
我的作业有限制,我应该使用 c++98 版本。
But during the implementation of "insert" function, i have problem which i explained in this link .但是在执行“插入”function 期间,我遇到了我在此链接中解释的问题。
I got some hints that i should use "enable_if" from link.我得到了一些提示,我应该使用链接中的“enable_if”。 But because I have no right to use c++11 (enable_if defined) extention so i made enable if and is_integral by myself.
但是因为我无权使用 c++11 (enable_if defined) 扩展,所以我自己启用了 if 和 is_integral。
This is previous one.这是上一个。
// 1
template <typename T, typename Alloc>
void vector<T, Alloc>::insert(iterator position, size_type n, const value_type &val)
// 2
template <typename T, typename Alloc>
template <class InputIterator>
void vector<T, Alloc>::insert(iterator position, InputIterator first, InputIterator last)
This is the code that i changed with custom enable_if and is_integral这是我用自定义 enable_if 和 is_integral 更改的代码
// 1
template <typename T, typename Alloc>
void vector<T, Alloc>::insert(iterator position, size_type n, const value_type &val)
// 2
template <typename T, typename Alloc>
template <class InputIterator, class = typename ft::enable_if<!ft::is_integral<InputIterator>::value>::type>
void vector<T, Alloc>::insert(iterator position, InputIterator first, InputIterator last)
It works well if i don't give "-std=c++98" option to compiler, but if i give it, it said如果我不给编译器“-std=c++98”选项,它会很好用,但如果我给它,它会说
./Vector.hpp:87:33: warning: default template arguments for a function template are a C++11 extension [-Wc++11-extensions]
...class = typename ft::enable_if<!ft::is_integral<InputIterator>::value>::type>
^
Could you please help me to adapt my code for c++98 extension?你能帮我修改我的代码以适应 c++98 扩展吗?
std::enable_if
and std::is_integral
were introduced in C++11.在 C++11 中引入了
std::enable_if
和std::is_integral
is_integral。 You can reimplement them like that if you compile with the --std=c++98
flag.如果您使用
--std=c++98
标志进行编译,您可以像这样重新实现它们。
You can find all the specifications to do that here and here .您可以在此处和此处找到执行此操作的所有规范。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.