小编Tom*_*pen的帖子

检查是否有效的模板专业化

我想检查一个模板是否可以使用给定的参数集进行专门化.以下是仅接受1个参数的模板版本:

#include <iostream>

template<template<typename...> class C, typename T>
struct is_valid_specialization {
    typedef struct { char _; } yes;
    typedef struct { yes _[2]; } no;

    template<template<typename...> class D, typename U>
    static yes test(D<U>*);
    template<template<typename...> class D, typename U>
    static no test(...);

    constexpr static bool value = (sizeof(test<C, T>(0)) == sizeof(yes));
};

template<typename T>
struct Test1 { };

template<typename T1, typename T2>
struct Test2 { };

template<typename...>
struct TestV { };

int main() {
    std::cout << "Test1<T>: " << is_valid_specialization<Test1, int>::value …
Run Code Online (Sandbox Code Playgroud)

c++ templates sfinae variadic-templates c++11

14
推荐指数
1
解决办法
594
查看次数

如何从Db2中的列中删除默认约束

我有一个表STUDENT_TB,它有一个STUDENT_ID,NAME,AGE列.我添加了一个包含以下命令的列: -

alter table STUDENT_TB add DOB TIMESTAMP NOT NULL DEFAULT CURRENT TIMESTAMP
Run Code Online (Sandbox Code Playgroud)

对于DOB列,我不希望它为null.现在我需要删除该默认约束.

我试过搜索但没有取得任何成功.

问候.

sql db2 default-constraint

5
推荐指数
1
解决办法
1万
查看次数

模板参数演绎

我目前正面临一个我无法解决的问题.基本上我正在尝试做的是在C++中实现一些类似linq的行为.

我将从头文件中的代码开始:

template<typename T, template<class = T> class A,
         template<class = T, template<class=T> class = A> class C>
class queryable
{
public:
    typedef T value_type;
    typedef A<value_type> allocator_type;
    typedef C<value_type, allocator_type> container_type;    // (1)
    typedef queryable<T, A, C> type;
    queryable(container_type const &) { }
    template<typename _Out> queryable<_Out, A, C> select(/* some delegate */);
    // more methods etc
}
Run Code Online (Sandbox Code Playgroud)

这就是我希望它被实例化的方式:

std::vector<int> my_vec;
queryable<std::vector<int> > q(my_vec);
Run Code Online (Sandbox Code Playgroud)

不用说这不起作用(其他我不会在这里:))

现在更奇怪的部分是,即使这似乎不起作用:

std::vector<int> my_vec;
queryable<int, std::allocator, std::vector> q(my_vec);
Run Code Online (Sandbox Code Playgroud)

正如您所看到的(通过查看select函数),对我来说不仅仅是使用这样的东西很重要:

template<typename T> class queryable;
Run Code Online (Sandbox Code Playgroud)

关于如何解决这个问题的任何建议?这甚至可能吗?

任何帮助,将不胜感激!

编辑:我得到的错误: …

c++ linq templates template-argument-deduction

5
推荐指数
2
解决办法
4378
查看次数

为什么GCC不能使用声明将其解析为正确的类型

在我正在研究的项目中进行编码时,我发现了一些非常奇怪的东西:

namespace detail {

    struct tuplelike_tag { };
    struct arraylike_tag { };

    template<typename>
    struct call_with_traits;

    template<typename... Ts>
    struct call_with_traits<std::tuple<Ts...>> {
        using tag = tuplelike_tag;

        enum { size = sizeof...(Ts) };
    };

    template<typename T, std::size_t Sz>
    struct call_with_traits<std::array<T, Sz>> {
        using tag = arraylike_tag;

        enum { size = Sz };
    };

    template<typename T, std::size_t Sz>
    struct call_with_traits<T[Sz]> {
        using tag = arraylike_tag;

        enum { size = Sz };
    };

    template<typename F, typename T, int... Is>
    auto call_with(F && f, T && …
Run Code Online (Sandbox Code Playgroud)

c++ templates using c++11

5
推荐指数
1
解决办法
338
查看次数

如何在boost 1.55中使用boost :: split和boost :: string_ref

代码:

#include <iostream>
#include <boost/algorithm/string.hpp>
#include <boost/utility/string_ref.hpp>

int main() 
{
    boost::string_ref str = "test_the_world";
    std::vector<boost::string_ref> strs;
    boost::split(strs, str, boost::is_any_of("_"), boost::token_compress_on);
    for (auto& v : strs)
    {
        std::cout << v << std::endl;
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

错误:

1>C:\boost_1_55_0\boost/range/iterator_range_core.hpp(643): error C2665: 'boost::basic_string_ref<char,std::char_traits<char>>::basic_string_ref' : none of the 4 overloads could convert all the argument types
1>          C:\boost_1_55_0\boost/utility/string_ref.hpp(79): could be 'boost::basic_string_ref<char,std::char_traits<char>>::basic_string_ref(const charT *,boost::basic_string_ref<charT,std::char_traits<char>>::size_type)'
1>          with
1>          [
1>              charT=char
1>          ]
1>          while trying to match the argument list '(const char *, const char …
Run Code Online (Sandbox Code Playgroud)

boost c++11

5
推荐指数
2
解决办法
1616
查看次数

带有自定义指针类型的unique_ptr:*get()和operator*()给出不同的输出

根据cppreference调用std::unique_ptr::operator*()相当于调用*(std::unique_ptr::get()).

但是我对两个电话都有不同的结果.这是我的代码:

#include <iostream>
#include <string>
#include <memory>

#include <fcntl.h>
#include <unistd.h>

struct file_descriptor
{
private:
  struct closer;

public:
  typedef int handle_type;
  typedef closer closer_type;

  constexpr static handle_type kInvalidHandle = -1;

public:
  file_descriptor(int handle = kInvalidHandle) : handle_{ handle } { }
  file_descriptor(std::nullptr_t) : file_descriptor{ } { }

  operator int&() { return handle_; }
  operator int() const { return handle_; }

  int& operator*() { return static_cast<int&>(*this); }
  int operator*() const { return static_cast<int>(*this); } …
Run Code Online (Sandbox Code Playgroud)

c++ c++11

2
推荐指数
1
解决办法
412
查看次数