implemented a SFINAE compile-time checker for receive policies
This commit is contained in:
		
							
								
								
									
										24
									
								
								check_policy.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								check_policy.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <type_traits>
 | 
			
		||||
#include "chat_messages.hpp"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* SFINAE compile-type checker for receive policies (as defined in chat_networking.hpp)
 | 
			
		||||
 * it checks whether PolicyCandidate supplies all of the following methods:
 | 
			
		||||
 *      - void message_do_what(chat_message)                                         */
 | 
			
		||||
template <class PolicyCandidate, typename = void>
 | 
			
		||||
struct is_valid_policy : std::false_type {};
 | 
			
		||||
 | 
			
		||||
template <class PolicyCandidate>
 | 
			
		||||
struct is_valid_policy<
 | 
			
		||||
        PolicyCandidate,
 | 
			
		||||
        typename
 | 
			
		||||
        std::enable_if<
 | 
			
		||||
                std::is_same<
 | 
			
		||||
                        decltype(PolicyCandidate
 | 
			
		||||
                                 ::message_do_what(std::declval<chat::chat_message>())),
 | 
			
		||||
                        void
 | 
			
		||||
                >::value
 | 
			
		||||
        >::type>
 | 
			
		||||
: std::true_type {};
 | 
			
		||||
		Reference in New Issue
	
	Block a user