小编Jos*_*osé的帖子

比较shared_ptr对象的相等性

是否有标准谓词来比较shared_ptr管理对象是否相等.

template<typename T, typename U>
inline bool target_equal(const T& lhs, const U& rhs)
{
    if(lhs && rhs)
    {
        return *lhs == *rhs;
    }
    else
    {
        return !lhs && !rhs;
    }
}
Run Code Online (Sandbox Code Playgroud)

我想要类似于上面的代码,但如果已经有一个标准的解决方案,将避免将其定义为我自己.

c++ c++11

7
推荐指数
2
解决办法
3609
查看次数

带有colorpicker编辑器的JavaFX tableview

我有一个TableView,它使用ColorPicker来(显示/编辑)单元格中的颜色.该表在所需字段中显示ColorPicker,但编辑不起作用.

TableColumn<SeriesPreferences, Color> c2 = new TableColumn<SeriesPreferences, Color>("Color");
c2.setCellValueFactory(new PropertyValueFactory<SeriesPreferences, Color>("color"));
c2.setCellFactory(new Callback<TableColumn<SeriesPreferences, Color>,
                                TableCell<SeriesPreferences, Color>>()
    {
        @Override
        public TableCell<SeriesPreferences, Color> 
        call(final TableColumn<SeriesPreferences, Color> param)
        {
            TableCell<SeriesPreferences, Color> cell = 
                new TableCell<SeriesPreferences, Color>()
                    {
                        @Override
                        public void updateItem(Color c, boolean empty)
                        {
                            if(c != null)
                            {
                                final ColorPicker cp = new ColorPicker();
                                cp.setValue(c);
                                setGraphic(cp);
                                cp.setOnAction(new EventHandler<javafx.event.ActionEvent>()
                                    {
                                        public void 
                                        handle(javafx.event.ActionEvent t)
                                        {
                                            getTableView().edit(getTableRow().getIndex(), param);
                                            commitEdit(cp.getValue());
                                        }
                                    });
                            }
                        }
                    };
            return cell;
        }
    });

c2.setOnEditCommit(new EventHandler<CellEditEvent<SeriesPreferences, Color>>()
    {
        @Override
        public …
Run Code Online (Sandbox Code Playgroud)

java javafx-2

6
推荐指数
1
解决办法
2532
查看次数

OS X clang -pthread

在OS X中使用带有clang的pthread库有什么编译器/链接器要求.

使用GCC我知道使用-pthread设置适当的编译器/链接器选项,但我不确定OS X与clang.

air:~ jose$ clang++ -c test.cpp -pthread
air:~ jose$ clang++ -o test -pthread test.o 
clang: warning: argument unused during compilation: '-pthread'

air:~ jose$ g++ -c test.cpp -pthread
air:~ jose$ g++ -o test -pthread test.o 
Run Code Online (Sandbox Code Playgroud)

c c++ macos clang

6
推荐指数
1
解决办法
9382
查看次数

C++初始化列表和默认值

这段代码对C++ 14有效吗?

using namespace std;
struct Point
{
  int x = 0;
  int y = 0;
};
Point p2 {1, 1};
Run Code Online (Sandbox Code Playgroud)

它使用clang ++ 7.0编译得很好,在两种情况下它都不适用于G ++ 4.9我将--std = c ++ 1y传递给编译器.

在G ++中,当我从结构定义中删除默认值时,它可以工作.

g++ test_constexpr_ctor.cc --std=c++1y -o test
test_constexpr_ctor.cc:7:15: error: no matching function for call to ‘Point::Point(<brace-enclosed initializer list>)’
Point p2 {1, 1};
            ^
test_constexpr_ctor.cc:7:15: note: candidates are:
test_constexpr_ctor.cc:1:8: note: constexpr Point::Point()
struct Point
        ^
test_constexpr_ctor.cc:1:8: note:   candidate expects 0 arguments, 2 provided
test_constexpr_ctor.cc:1:8: note: constexpr Point::Point(const Point&)
test_constexpr_ctor.cc:1:8: note:   candidate …
Run Code Online (Sandbox Code Playgroud)

c++ g++ c++14

6
推荐指数
1
解决办法
487
查看次数

knuth乘法哈希

这是Knuth乘法散列的正确实现吗?

int hash(int v)
{
    v *= 2654435761;
    return v >> 32;
}
Run Code Online (Sandbox Code Playgroud)

乘法中的溢出会影响算法吗?

如何提高这种方法的性能?

c++ algorithm hash

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

JavaFX折线图中的空指针异常

我在Swing应用程序中使用JavaFX LineChart,当尝试清除系列数据时,我得到了这个异常.

我的代码只调用clear方法,调用是在使用Platform.runLater的JavaFX线程中进行的,我在ubuntu上使用1.7.0_09,我的代码是否存在任何问题,或者这是JavaFX中的错误.

series.getData().clear();
Run Code Online (Sandbox Code Playgroud)

series是一个XYChart.Series对象

Exception in runnable
java.lang.NullPointerException
at javafx.scene.chart.LineChart.dataItemRemoved(LineChart.java:275)
at javafx.scene.chart.XYChart.dataItemsChanged(XYChart.java:470)
at javafx.scene.chart.XYChart.access$2500(XYChart.java:72)
at javafx.scene.chart.XYChart$Series$1.onChanged(XYChart.java:1462)
at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:134)
at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:48)
at com.sun.javafx.collections.ObservableListWrapper.callObservers(ObservableListWrapper.java:97)
at com.sun.javafx.collections.ObservableListWrapper.clear(ObservableListWrapper.java:184)
Run Code Online (Sandbox Code Playgroud)

javafx-2

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

检测临时ipv6地址跨平台

我想检测一个地址是否是临时ipv6地址,我使用getifaddrs获取地址列表但不知道如何从那里获取该信息.如果可能的话,我希望它适用于linux,osx,solaris和windows.

我似乎在Linux中IFA_F_TEMPORARY设置在inet6_ifaddr-> ifa_flags中,但不确定我是如何从getifaddrs返回的ifaddrs中获取的.

似乎在OSX上我需要octl和SIOCSIFINFO_FLAGS,我不知道Solaris或Windows.

有任何机构可以做到这一点的示例代码.

c network-programming

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

Closure默认捕获开销

使用默认捕获模式有任何开销吗?

{
   Foo foo = ...;
   Bar bar = ...;
   [&]()
   {
       write(foo);
   }
}

{
   Foo foo = ...;
   Bar bar = ...;
   [&foo]()
   {
       write(foo);
   }
}
Run Code Online (Sandbox Code Playgroud)

澄清是否有任何使用前者的成本,即使没有使用,也会被捕获?

c++ lambda c++14

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

算法使用32位无符号整数乘以64位数

我有64位数字(63位+符号位),表示为二进制补码数,存储在两个无符号32位整数中.

struct Long
{
    uint32 high;
    uint32 low;
}
Run Code Online (Sandbox Code Playgroud)

如何实现一个乘法算法,只使用32位数,并检查结果是否适合63位,我想返回一个错误代码,如果结果不合适则表示溢出.

c c++ algorithm

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

项目加载的Eclipse插件

我有一个插件,想要检测何时将项目添加到工作区,从我的插件代码中设置一些项目设置,Any Ideas.

特别是我想在一些衍生文件的资源中调用setHidden,因为这个设置似乎不是项目的一部分,我的意思是,如果我在新工作区中导入项目,隐藏资源似乎不会持久.

eclipse eclipse-plugin

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

JavaFX LineChart图例样式

我想更新LineChart图例的样式,我在具有相应系列类的节点上使用setStyle。

String color = ....
XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
_chart.getData().add(series);

String seriesClass = null;
for(String styleClass : series.getNode().getStyleClass())
{
    if(styleClass.startsWith("series"))
    {
        seriesClass = styleClass;
        break;
    }
}
if(seriesClass != null)
{
    //
    // Customize the style.
    //
    StringBuilder sb = new StringBuilder();
    sb.append("-fx-stroke: ");
    sb.append(color);
    sb.append("; ");
    sb.append("-fx-background-color: ");
    sb.append(color);
    sb.append(", white;");
    if(doted)
    {
        sb.append("-fx-stroke-dash-array: 10 10");
    }
    _styles.put(seriesClass, sb.toString()); 
}

java.util.Set<javafx.scene.Node> nodes = _chart.lookupAll("." + seriesClass);
for(javafx.scene.Node n : nodes)
{
    n.setStyle(style);
}
Run Code Online (Sandbox Code Playgroud)

事实是,这只会影响路径的样式,图例样式不会改变。我已经打印了图表节点的子级,并发现在添加系列调用返回后未完全创建图例:

Legend@18e8627[styleClass=chart-legend]
    Label@1689c98[styleClass=label …
Run Code Online (Sandbox Code Playgroud)

java javafx-2

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