小编Ole*_*nko的帖子

用于pImpl成语的std :: auto_ptr或boost :: shared_ptr?

当使用pImpl习语时,最好使用a boost:shared_ptr而不是std::auto_ptr?我确定我曾经读过增强版更加异常友好吗?

class Foo
{
public:
    Foo();
private:
    struct impl;
    std::auto_ptr<impl> impl_;
};

class Foo
{
public:
    Foo();
private:
    struct impl;
    boost::shared_ptr<impl> impl_;
};
Run Code Online (Sandbox Code Playgroud)

[编辑]使用std :: auto_ptr <>是否总是安全的,或者是否需要使用替代的boost智能指针?

c++ boost stl auto-ptr shared-ptr

16
推荐指数
2
解决办法
9683
查看次数

删除重复的行(不要删除所有重复的行)

我正在使用postgres.我想删除重复行.条件是,不会删除重复行集中的1个副本.

即:如果有5个重复记录,那么其中4个将被删除.

sql postgresql duplicate-removal

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

map <string,string>如何在此地图中插入数据?

我需要以键值格式存储字符串.所以我正在使用如下的地图.

#include<map>
using namespace std;
int main()
{
    map<string, string> m;
    string s1 = "1";
    string v1 = "A";

    m.insert(pair<string, string>(s1, v1)); //Error
}
Run Code Online (Sandbox Code Playgroud)

我在插入行时遇到错误

错误C2784:'bool std :: operator <(const std :: _ Tree <_Traits>&,const std :: _ Tree <_Traits>&)':无法推断'const std :: _ Tree <_Traits>&'的模板参数来自'const std :: string'

我也尝试过make_pair函数,但是这也报告了同样的错误.

m.insert(make_pair(s1, v1));
Run Code Online (Sandbox Code Playgroud)

请告诉我什么是错的,以及解决上述问题的方法是什么.解决了上述问题后,我可以使用下面的方法来检索基于密钥的值

m.find(s1);
Run Code Online (Sandbox Code Playgroud)

c++ stl stdmap stdstring

12
推荐指数
4
解决办法
7万
查看次数

通过Powershell进行智能图像搜索

我对通过自定义属性进行文件搜索感兴趣.例如,我想找到具有特定尺寸的所有JPEG图像.看起来像

Get-ChildItem -Path C:\ -Filter *.jpg -Recursive | where-object { $_.Dimension -eq '1024x768' }
Run Code Online (Sandbox Code Playgroud)

我怀疑它是关于使用System.Drawing的.怎么做?提前致谢

powershell image file-search

9
推荐指数
1
解决办法
2024
查看次数

在不同的命名空间中测试特定的类名(SFINAE?)

假设我在不同的命名空间中有几个具有相同名称的类.

namespace A { class Foo { ... }; }
namespace B { class Foo { ... }; }
namespace C { class Foo { ... }; }
Run Code Online (Sandbox Code Playgroud)

我想在编译时检测出Foo尽管命名空间命名的类.例如一些SFINAE类,

template <typename T> struct is_Foo {
  static const bool value = /* some magic here */;
}; 
Run Code Online (Sandbox Code Playgroud)

然后我想要的is_Foo<A::Foo>::value是真的,is_Foo<B::Foo>::value是真的,is_Foo<A::Bar>::value是假的.

然后,我想使用is_Foostatic_assertstd::enable_if.可能吗?

c++ templates namespaces sfinae c++11

4
推荐指数
1
解决办法
202
查看次数

ptr_map插入

我有一些继承boost :: noncopyable的预定义类型(所以我必须将指针存储在这些对象中).我使用boost :: ptr_map.据我所知,其中的第二个参数已经是一个指针.所以,代码:

ptr_map<string, boost::any> SomeMap;
typedef %Some noncopyable class/signature% NewType;

// Inserting now
boost::any *temp = new boost::any(new KeyEvent());
SomeMap.insert("SomeKey", temp);
Run Code Online (Sandbox Code Playgroud)

错误是:

error: no matching function for call to ‘boost::ptr_map<std::basic_string<char>, boost::any>::insert(const char [11], boost::any*&)’


UPD:当我没有将指针传递给any时any temp = any(new KeyEvent());

我明白了:

error: no matching function for call to ‘boost::ptr_map<std::basic_string<char>, boost::any>::insert(const char [11], boost::any&)’

c++ boost types insert boost-ptr-container

3
推荐指数
1
解决办法
6911
查看次数

最快的稳定重复删除算法

我有一个数组,我需要摆脱它的数组,没有重复.我必须保留原始数组中具有最小顺序的那些唯一元素.这大致是我的意思

NoDuplicate(A, value)
  for int i = 0 to i < A.length
    if A[i] == value
      return true
    i++
  return false

StableRemoveAlgo(A)      
  for int i = 0 to i < A.length
    if NoDuplicate(result, A[i])
      result.append(A[i])
  return result
Run Code Online (Sandbox Code Playgroud)

如果算法比这个简单算法快?

更新:我无法对数组进行排序.我需要一个"稳定"版本的重复删除算法.所以,如果A[i] == A[j] and i < j算法必须删除元素A[j]

language-agnostic algorithm duplicate-removal

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