RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-236158

Jens's questions

Martin Hope
Jens
Asked: 2020-04-21 18:36:05 +0000 UTC

如何以二进制输出 MySQL 数据类型表示?

  • 1

像这样尝试:

select cast(convert('1900-01-02 00:00:01.000000', datetime(6)) AS BINARY)

明白啦:

4957484845484945485032484858484858484946484848484848

这些只是 ASCII 字符代码,但 datetime(6) 是 8 个字节,我想要这 8 个字节的内容。convert 而不是 cast 没有帮助。对日期时间感兴趣 (6)。这种方法适用于 MS SQL Server,但由于某种原因,MySQL 的行为不同。

mysql
  • 2 个回答
  • 10 Views
Martin Hope
Jens
Asked: 2020-10-26 21:15:57 +0000 UTC

通过 Boost.Python 并行执行 Python 函数

  • 1

数据部分:

static Market market;

// boost::asio::thread_pool thread_pool;

static std::unordered_map < std::string, std::unordered_map < std::string,
    std::pair < Market::path_t, std::string > > > data; // future

Python设置:

static Python_Initializer python_initializer;

static boost::python::object global = boost::python::import("__main__").attr("__dict__");

boost::python::exec("from analysis.src.main import run", global, global);

static boost::python::object module = global["run"];

在Python_Initializer被称为Py_Initialize。static这里和数据部分需要避免重新构造对象,因为 此代码放置在从外部循环调用的库的 DLL 函数中。该函数run是线程安全的。

主要执行:

for (const auto & asset : market.assets())
{
    for (const auto & scale : market.scales())
    {
        auto file = market.get(asset, scale, 250);

        //std::packaged_task < std::string() > task([asset, scale, file, &module]()
        //{
        //    return boost::python::extract < std::string > (
        //      module(asset.c_str(), scale.c_str(), file.string().c_str()));
        //});

        //data[asset][scale] = std::make_pair(std::move(file),
        //  boost::asio::post(thread_pool, std::move(task)));

        std::string message = boost::python::extract < std::string >(
            module(asset.c_str(), scale.c_str(), file.string().c_str()));

        data[asset][scale] = std::make_pair(std::move(file), std::move(message));
    }
}

在当前的串行执行中,一切正常。但是,如果添加thread_pool,将后者包裹在std::string中data,std::future并将主执行中的代码替换为当前注释掉的代码,则会发生错误。它的内容没有说什么具体的,错误是在Boost.Python级别的,如果你跟踪它,那么在设置某种回调函数时读/写指针有问题。

问题:如何配置Boost.Python,让Boost的并行执行机制和标准库可以并行执行一些线程安全的Python函数?

c++
  • 1 个回答
  • 10 Views
Martin Hope
Jens
Asked: 2020-08-27 18:31:11 +0000 UTC

创建 const 实例时构造函数中的非 const 方法

  • 0

为什么如果我们创建const一个类的实例并在构造函数中调用该类的成员函数,而这不在签名中const- 一切都很好?毕竟,当构造函数的主体被执行时,类实例已经被创建了?

class X
{
public:
    X(...) : ...
    {
        f(); // ok
    }

    void f()
    {
        // ...
    }
}

const X x; // ok

x.f() // error
c++
  • 1 个回答
  • 10 Views
Martin Hope
Jens
Asked: 2020-08-23 03:01:49 +0000 UTC

在一组无序的自定义类实例中进行搜索优化

  • 1

让我们考虑一个存储自定义类实例的无序集,而散列仅在此类的一个字段上执行。为了找到所需的元素,我们使用 find 算法。但是,该算法还需要此类的完整实例,而不仅仅是单个可散列字段。问题:在无序集合中搜索并仅使用一个字段时,是否有可能以某种方式摆脱类的此服务实例的创建?

c++
  • 1 个回答
  • 10 Views
Martin Hope
Jens
Asked: 2020-10-09 19:11:01 +0000 UTC

归档过时的数据库数据

  • 1

我有一个使用数据库的 Django 项目。任务是使用特殊脚本从数据库中删除过时的对象。但是您不想永远删除已删除的对象,而是想将它们保存在某个地方。例如,在一些存档数据库中。该问题的一个可能解决方案是存储两个数据库 - 一个用于服务器,另一个用于存档。然后,在从服务器数据库中删除对象之前,需要将对象复制到存档数据库。它是如何实施的?还是原则上使用其他方法来解决此类问题?

python
  • 1 个回答
  • 10 Views
Martin Hope
Jens
Asked: 2020-09-06 06:18:24 +0000 UTC

在控制台中使用 unicode

  • 1

我正在使用 MS VS 201,Win 7。以下代码输出错误的字符:

system("chcp 65001");

std::cout << "\x00FF" << std::endl;

问题是什么?即使更改了代码页,控制台也对 Unicode 不友好?

c++
  • 2 个回答
  • 10 Views
Martin Hope
Jens
Asked: 2020-03-15 01:19:14 +0000 UTC

在 std::call_once 中改变被动执行线程的行为

  • 0

如何使两个线程的std::call_once行为如下:其中一个(其中一个)将开始主动执行 in 中的函数call_once,而另一个将执行而不是被动等待abort()或以某种方式中断?

问题来自如何制作,即在多线程中仅提供某个类的调用 k-ra 一次。到目前为止,想法是在构造函数中进行调用std::call_once(flag, init),其中init()有一些初始化函数。然后添加类似assert(called == 0). 也许我错了,你能让打电话更容易吗?

c++
  • 1 个回答
  • 10 Views
Martin Hope
Jens
Asked: 2020-03-13 18:36:39 +0000 UTC

关于使用make_uniuque的语法问题

  • -1

请告诉我如何在语法上更正这一行:

m_instance.reset(new T(std::forward < Args > (args) ...));

使用std::make_unique?不管我怎么试,它都写它不能匹配模板参数_Ty,找不到对应的重载函数等等。

template < typename ... Args >
static void construct(Args && ... args)
{
    m_instance.reset(new T(std::forward < Args > (args) ...));
}

这是模板类的静态函数的一般形式。m_instance- 这个static std::unique_ptr < T >。我想删除new并设置m_instance通过make_uniuque,像这样:m_instance(std::make_unique( /* а тут что ? */ ))。怎么写...?std::make_unique

c++
  • 1 个回答
  • 10 Views
Martin Hope
Jens
Asked: 2020-03-13 01:21:54 +0000 UTC

禁止从标准库中复制和移动互斥锁

  • 0

在文件的源代码中我找不到禁止移动操作。明确禁止复制= delete,因此

_Mutex_base(const _Mutex_base&) = delete;
_Mutex_base& operator=(const _Mutex_base&) = delete;

所以:

mutex(const mutex&) = delete;
mutex& operator=(const mutex&) = delete;

为什么需要两次?是的,为什么没有旅行禁令?他晦涩难懂吗?

c++
  • 1 个回答
  • 10 Views
Martin Hope
Jens
Asked: 2020-02-28 00:24:57 +0000 UTC

使用 operator= 进行隐式类型转换是什么意思?

  • 0

这句话是什么意思,可以通过赋值运算符执行某些用户定义类的实例的隐式转换(除了非显式构造函数和转换运算符)?这里隐含什么?那些。我们a = b在a它有 typeA和b其他 type的地方B写,而我们显式地写 sign =,从而表明调用了这样和这样的运算符,它将把这个写到b我们的实例中。使用非显式的 k-s,一切都很清楚:我们void f(A)以形式调用某个函数f(b)- 很明显,某些 k-r 被隐式​​调用,我们不写任何额外的字符。问题来自这里,请参阅类的隐式转换。

c++
  • 1 个回答
  • 10 Views
Martin Hope
Jens
Asked: 2020-02-26 18:38:20 +0000 UTC

在 SFINAE 中为具有完美转发的构造函数使用什么类型的关系?

  • 1

与 SFINAE 中的类型检查有些混淆。假设有:

class Foo
{
public:
    std::string member;
    std::string member2;

    template <
        typename T, // Parameter 1.
        typename U, // Parameter 2.
        typename Enable = typename std::enable_if <
        std::is_constructible<std::string, T>::value &&
        std::is_constructible<std::string, U>::value>::type>
    Foo(T&& member, U&& member2) :
        member{std::forward<T>(member)},
        member2{std::forward<U>(member2)}
    {}
};

我不明白该使用什么,std::is_constructible或者std::is_convertible?std::is_same关于后者,据我了解,给我们提供了一个艰难的巧合,我们std::decay只能添加更多。但是,我想使用 C 数组或例如通过std::initializer_list. 我std::is_convertible知道它会跳过,例如,转换float为int,但在这段代码中:

template<class D>
    impl_ptr(pointer p, D&& d,
             typename std::enable_if<
                std::is_convertible<D, deleter_type>::value,
                dummy_t_
             >::type = dummy_t_()) noexcept
    : ptr_(std::move(p), std::forward<D>(d)) {}

被使用(这个例子是一个智能指针构造函数,用于实现 pimpl,D并且deleter_type是删除器,ptr_类型为std::unique_ptr)。

c++
  • 2 个回答
  • 10 Views
Martin Hope
Jens
Asked: 2020-02-21 00:06:57 +0000 UTC

这样的复制构造函数是如何工作的?

  • 1

有一个复制构造函数:

Implementation(const Implementation &  other) :
    Implementation(other.clone())
{}

还有一个功能clone():

Implementation Implementation::clone() const 
{
    return Implementation(this->number(), this->string(), this->vector());
}

移动构造函数:

Implementation(      Implementation && other) noexcept :
    Implementation()
{
    this->swap(other);
}

我不明白为什么不在线调用Implementation(other.clone())移动构造函数(定义了移动构造函数)。毕竟,该函数clone()只返回调用它的对象的副本。什么叫做?

c++
  • 1 个回答
  • 10 Views
Martin Hope
Jens
Asked: 2020-12-15 18:51:45 +0000 UTC

从 ENUM_E_MACHINE 字典中获取数字而不是字符串

  • 1

格式文件ELF存储架构类型。有pyelftools一本字典在:

ENUM_E_MACHINE = dict
(
    EM_NONE  = 0, # No machine
    EM_M32   = 1, # AT&T WE 32100
    EM_SPARC = 2, # SPARC
    ...
)

用户界面适用于从 this 返回字符串enum。

但是需要从字典中获取一个数字(结果是获取一个字符串)。例如 :

print something.elf['e_machine'] 
print something.elf.header.e_machine

它输出一个字符串。例如,EM_X86_64或EM_M32。如何直接或间接使用该库从字典中获取与机器类型相对应的数字,而不是字符串?

python
  • 1 个回答
  • 10 Views
Martin Hope
Jens
Asked: 2020-11-25 23:59:11 +0000 UTC

使用 std::forward 在构造函数中进行类型检查

  • 3
class A
{
public:
    using number_t = std::int32_t;
    using string_t = std::string;

    template < class T >
    using vector_t = std::vector < T >;

public:
    template < class T1, class T2, class T3 >
    A(T1 && n, T2 && s, T3 && v) :
        m_n { std::forward < T1 > (n) },
        m_s { std::forward < T2 > (s) },
        m_v { std::forward < T3 > (v) } {}

private:
    number_t              m_n;
    string_t              m_s;
    vector_t < number_t > m_v;
};

问题:我需要在构造函数中检查T1,T2的类型吗?T3我认为这是必要的,因为这个构造函数很容易吃掉,例如,作为第一个参数double,这是不可取的。如何正确检查?我正在考虑std::enable_if_t和std::is_same。如果是这样,如果构造函数接受左值,如何删除引用?编译器抱怨std::is_same < number_t, std::remove_reference< T1 >::type >::value. 写道:“需要一种类型,而不是这个类型。”

c++
  • 2 个回答
  • 10 Views
Martin Hope
Jens
Asked: 2020-11-24 14:58:28 +0000 UTC

PIMPL 在唯一或共享指针上?

  • 3

以下是此站点中 pImpl 习语的实现代码。

// in header file
class widget 
{
public:
    widget();
    ~widget();
private:
    class impl;
    unique_ptr<impl> pimpl;
};

// in implementation file
class widget::impl 
{
    // :::
};

widget::widget() : pimpl{ new impl{ /*...*/ } } { }
widget::~widget() { }

此外,它说以下内容:

更喜欢使用 unique_ptr 来保存 Pimpl。它比使用 shared_ptr 更有效,并且正确地表达了不应该共享 Pimpl 对象的意图。

问题:使用的效率(首选更快的移动?)究竟是什么,std::unique_ptr为什么建议不要跨多个实例共享实现?我之前问过一个关于写时复制习语的问题,为什么不在类型指针上使用 pImpl 习语的实现,shared_ptr并用以下特定于 COW 习语的运算符实现来补充它:

    // Non-const * and -> , copying
    T& operator*()
    {
        copy();
        return *m_sp;
    }

    T* operator->()
    {
        copy();
        return m_sp.operator->();
    }

    // Const * and -> methods no need to copy
    const T& operator*() const
    {
        return *m_sp;
    }

    const T* operator->() const
    {
        return m_sp.operator->();
    }
c++
  • 2 个回答
  • 10 Views
Martin Hope
Jens
Asked: 2020-11-23 22:35:08 +0000 UTC

实现写时复制习语

  • 2

在Scott Myers 的书“ The Most Effective Use of C++”中,第 29 项提供了一个类组实现,Widget通过创建一个RCWidget包含指针RCIPtr<Widget>和重定向函数的包装类来为自定义类提供服务。这种机制对应于现代机制std::shared_ptr,除了在 Myers 机制中,当通过指针更改数据时,可以将其与其余部分分开并创建数据的副本,即 该值被拆分,直到它在其中一个指针中发生更改 - 然后制作一个额外的副本。

问题是,这种实现在今天的 C++ 标准中是否可以接受,如果不能,应该在哪里改进?在 boost 或其他地方是否有这种插件机制的实现?

PS我没有附上代码,一本书和一部手机就在手边,在2.5页,如果有人有电子版,请加。

c++
  • 2 个回答
  • 10 Views
Martin Hope
Jens
Asked: 2020-11-17 17:49:49 +0000 UTC

2 个赋值运算符还是一个?

  • 7

所以有两个赋值运算符——复制和移动,例如:

Implementation& operator= (const Implementation &  other) noexcept;
Implementation& operator= (      Implementation && other) noexcept;

话虽如此,这个问题(在第一个答案中)表明声明这样的运算符有一定的优势=,即 按价值:

Implementation& operator= (      Implementation    other) noexcept;

那些。在这种情况下,我们不能声明一个接受&&? 否则,只会有不确定性。那么,为什么是标准库中使用的第一种技术,但在 boost 中你可以找到:

#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
        template < typename ValueType >
        any& operator= (const ValueType& rhs)
        {
            any(rhs).swap(*this);
            return *this;
        }

        any& operator= (any rhs)
        {
            any(rhs).swap(*this);
            return *this;
        }
#else 
        any& operator= (const any& rhs)
        {
            any(rhs).swap(*this);
            return *this;
        }

        any& operator= (any&& rhs) BOOST_NOEXCEPT
        {
            rhs.swap(*this);
            any().swap(rhs);
            return *this;
        }
#endif

为什么不在第二个预处理器块中进行相同的实现:

        any& operator= (any rhs)
        {
            any(rhs).swap(*this);
            return *this;
        }

还是为了重置=接受运算符中的值而完成的?&&rvalue

c++
  • 1 个回答
  • 10 Views
Martin Hope
Jens
Asked: 2020-11-17 03:16:48 +0000 UTC

getter函数的实现

  • 1

如何正确实现getter函数?我的意思是返回值。所以:

std::shared_ptr<const number_t> number () const noexcept
{
    return std::make_shared<const number_t> (this->m_number);
}

或者像这样(vector::at 风格):

const auto & number () const noexcept
{
    return this->m_number;
}

m_number- 自定义类型字段,而不是标准字段。

现在哪个选项被认为是好的风格/更安全/更舒适等?

c++
  • 1 个回答
  • 10 Views
Martin Hope
Jens
Asked: 2020-11-17 02:46:50 +0000 UTC

复制和移动构造函数的“显式”

  • 6

是否有必要(如果需要,在什么情况下)将复制和移动构造函数指定为explicit?我在代码中看到了这一点,并不太明白。explicit帮助我们避免的不必要的隐式转换在哪里?

c++
  • 4 个回答
  • 10 Views
Martin Hope
Jens
Asked: 2020-11-09 22:09:47 +0000 UTC

为什么 operator++ 必须返回 const T?

  • 4
const T T::operator++(int)
{
    T tmp = *this;
    ++(*this);
    return tmp;
}

让我们考虑这种后缀递增运算符的实现变体。为什么需要准确返回const T而不是返回T?此选项是为 type 实现的int,但我是否需要以相同的方式为我的自定义类型实现此运算符?

我坚持了一个潜规则,在开发类(类型)时,如果不清楚(或尚未制定)所需的行为,那么你应该组织提供的行为int。int返回const int。我也需要吗?

c++
  • 3 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5