zoukankan      html  css  js  c++  java
  • C++中如何使用switch字符串

    switch

     typedef std::uint64_t hash_t;
    
    constexpr hash_t prime = 0x100000001B3ull;
    constexpr hash_t basis = 0xCBF29CE484222325ull;
    
    hash_t hash_(char const* str)
    {
    hash_t ret{ basis };
    
    while (*str) {
    ret ^= *str;
    ret *= prime;
    str++;
    }
    
    return ret;
    }
    
    constexpr hash_t hash_compile_time(char const* str, hash_t last_value = basis)
    {
    return *str ? hash_compile_time(str + 1, (*str ^ last_value) * prime) : last_value;
    }
    
    constexpr unsigned long long operator "" _hash(char const* p, size_t)
    {
    return hash_compile_time(p);
    }
    //--------------------------usage--------------------------//  
    //oid simple_switch(char const* str)
    //{
    // using namespace std;
    // switch (hash_(str)) {
    // case "first"_hash:
    // cout << "1st one" << endl;
    // break;
    // case "second"_hash:
    // cout << "2nd one" << endl;
    // break;
    // case "third"_hash:
    // cout << "3rd one" << endl;
    // break;
    // default:
    // cout << "Default..." << endl;
    // }
    //}
    //--------------------------usage--------------------------//  
    
  • 相关阅读:
    排序算法
    各种容器
    avl树
    zhenya moves from parents
    maven 相关
    Spring Cloud 子项目介绍
    WebStorm 中 dva 项目用 start 命令需要不断重启项目问题
    git常用命令
    SQL 的各种 join 用法
    程序员成长过程
  • 原文地址:https://www.cnblogs.com/lobsterIT/p/5654145.html
Copyright © 2011-2022 走看看