C++实现编译期快排-模板元编程

https://blog.csdn.net/huanghongxun/article/details/85065406

参考于上面的博客,但具体实现不一样。

#pragma once
#include
namespace mystd {
	template 
	struct integral_constant {
		static constexpr T value = v;
		typedef T value_type;
		//constexpr operator T() const noexcept { return value; }
		//constexpr T operator()() const noexcept { return value; }
	};

	template 
	using integer_constant = integral_constant;

	//实现列表结构
	template 
	struct integral_sequence { typedef T value_type;};

	template 
	using integer_sequence = integral_sequence;

	//求长
	template
	struct mylength {};

	template
	struct mylength,T> :integral_constant {};

	template
	using length=mylength;



	template
	struct push_front_t {};

	template
	struct push_front_t> { using type=integral_sequence; };

	template
	using push_front=typename push_front_t::type;

	//push_back
	template
	struct push_back_t {};

	template
	struct push_back_t> { using type=integral_sequence; };

	template
	using push_back=typename push_back_t::type;


	//print
	template 
	struct print { };

	template
	struct print> {
		static void print_integer() {
			std::cout << start << ' ';
			print>::print_integer();
		}
	};
	template<>
	struct print> {
		static void print_integer() { ; }
	};

	//empty
	template
	struct empty;
	template<>
	struct empty> :std::true_type {};

	template
	struct empty> :std::false_type {};


	//条件
	template
	struct conditional {};

	template
	struct conditional { using type=T; };

	template
	struct conditional { using type=F; };

	//map
	templatetypename Mapper, typename integer_sequence>
	struct map_t;

	templatetypename Mapper>
	struct map_t> {
		using type=integer_sequence<>;
	};

	templatetypename Mapper,int head,int ...tails>
	struct map_t> {
		using type=push_front::value,typename map_t>::type>;
	};

	templatetypename Mapper,typename T>
	using map = typename map_t::type;

	template
	struct increment {static constexpr int value=i+1;};


	//
	templatetypename Mapper,int compare, typename integer_sequence>
	struct filter;

	templatetypename Mapper,int compare>
	struct filter> { using type=integer_sequence<>; };


	templatetypename Mapper,int compare, int head, int ...tails>
	struct filter> {
		using type= typename conditional < Mapper::value,
			push_front>::type>,
			typename filter>::type>::type;
	};

	template
	struct big {
		static constexpr bool value = (i > j);
	};
	template
	struct low {
		static constexpr bool value = (i <= j);
	};
	

	//CONCAT
	template
	struct concat;

	template
	struct concat> {
		using type=T;

	};
	template
	struct concat> {
		using type=typename concat, integer_sequence>::type;

	};


	
	template
	struct quick_sort {};
	template<>
	struct quick_sort> {
		using type=integer_sequence<>
			;
	};

	template
	struct quick_sort >{
		using type=typename concat>::type>::type,
				typename concat, 
					typename quick_sort>::type>::type>::type>::type;
	};
	
	

}
#include
#include"test.h"
#include

using namespace mystd;
void main() {
	//print>::type>::print_integer();
	print>::type>::print_integer();
}

 

你可能感兴趣的:(C++实现编译期快排-模板元编程)