📄 ycpp_functional.hpp
字号:
/*
* The young Library
* Copyright (c) 2005 by Yang Huan(杨桓)
* Permission to use, copy, modify, distribute and sell this software for any
* purpose is hereby granted without fee, provided that the above copyright
* notice appear in all copies and that both that copyright notice and this
* permission notice appear in supporting documentation.
* The author make no representations about the suitability of this software
* for any purpose. It is provided "as is" without express or implied warranty.
*/
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#ifndef __MACRO_CPLUSPLUS_YOUNG_LIBRARY_FUNCTION_OBJECT_HEADER_FILE__
#define __MACRO_CPLUSPLUS_YOUNG_LIBRARY_FUNCTION_OBJECT_HEADER_FILE__
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
#include "../youngc/yc_function.h"
#include "ycpp_string.hpp"
//------------------------------------------------------------------------------
namespace youngcpp {
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
template< typename CharT >
size_t hash_string( const CharT* s, size_t len )
{
size_t h = 0;
for( ; len > 0; --len,++s )
h = (h << 5) - h + *s;
return h;
}
template< typename T >
struct hash {};
template< typename T >
struct hash<T*>
{
size_t operator()( T* x ) const { return reinterpret_cast<size_t>(x); }
};
template<>
struct hash<char*>
{
size_t operator()( char* x ) const { return youngc::hash_str(x); }
};
template<>
struct hash<wchar_t*>
{
size_t operator()( wchar_t* x ) const { return youngc::hash_wstr(x); }
};
template<>
struct hash<bool>
{
size_t operator()( bool x ) const { return x; }
};
template<>
struct hash<char>
{
size_t operator()( char x ) const { return x; }
};
template<>
struct hash<unsigned char>
{
size_t operator()( unsigned char x ) const { return x; }
};
template<>
struct hash<signed char>
{
size_t operator()( unsigned char x ) const { return x; }
};
template<>
struct hash<short>
{
size_t operator()(short x) const { return x; }
};
template<>
struct hash<unsigned short>
{
size_t operator()( unsigned short x ) const { return x; }
};
template<>
struct hash<int>
{
size_t operator()( int x ) const { return x; }
};
template<>
struct hash<unsigned int>
{
size_t operator()( unsigned int x ) const { return x; }
};
template<>
struct hash<long>
{
size_t operator()( long x ) const { return x; }
};
template<>
struct hash<unsigned long>
{
size_t operator()( unsigned long x ) const { return x; }
};
#ifdef __MACRO_CPLUSPLUS_YOUNG_LIBRARY_COMPILER_SUPPORT_LONG_LONG_TYPE__
template<>
struct hash<long long>
{
size_t operator()( long long x ) const { return x; }
};
template<>
struct hash<unsigned long long>
{
size_t operator()( unsigned long long x ) const { return x; }
};
#endif
template<>
struct hash<float>
{
size_t operator()( float x ) const
{ return youngc::hash_float(&x); }
};
template<>
struct hash<double>
{
size_t operator()( double x ) const
{ return youngc::hash_double(&x); }
};
template<>
struct hash<long double>
{
size_t operator()( long double x ) const
{ return youngc::hash_ldouble(&x); }
};
template< typename C, typename T, typename A >
struct hash< basic_string<C, T, A> >
{
size_t operator()( basic_string<C, T, A>& s ) const
{ return hash_string( s.c_str(), s.size() ); }
};
template< typename C, typename T, typename A >
struct hash< shared_string<C, T, A> >
{
size_t operator()( shared_string<C, T, A>& s ) const
{ return hash_string( s.c_str(), s.size() ); }
};
#ifndef __BORLANDC__
template< typename C, typename T, typename A >
struct hash< std::basic_string<C, T, A> >
{
size_t operator()( std::basic_string<C, T, A>& s ) const
{ return hash_string( s.c_str(), s.size() ); }
};
#endif
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
} //end namespace
#endif
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -