C++实战项目TinySTL之六:functional.h

最近看了《STL源码剖析》和侯捷老师的STL课程,打算做一个小型的STL,在增加项目经验的同时也顺带复习STL和数据结构相关的知识。整个系列完全参考岚岚路的博客和github上的一个STL项目项目地址

任务

functional中重载了小于和等于两个运算符

#pragma once
#ifndef  _FUNCTIONAL_H_
#define _FUNCTIONAL_H_

namespace mySTL {
    
    
	template<class T>
	struct less//顾名思义是个比大小的类
	{
    
    
		typedef T first_argument_type;
		typedef T second_argument_type;
		typedef bool result_type;

		result_type operator()(const first_argument_type& x, const second_argument_type& y) {
    
    
			return x < y;
		}
	};
	template<class T>
	struct equal_to
	{
    
    
		typedef T first_argument_type;
		typedef T second_argument_type;
		typedef bool result_type;

		result_type operator()(const first_argument_type& x, const second_argument_type& y) {
    
    
			return x == y;
		}
	};

}
#endif // ! _FUNCTIONSL_H_

猜你喜欢

转载自blog.csdn.net/weixin_44537258/article/details/115111517