完美的转发/移动构造在std :: apply中的tuple中不起作用

时间:2018-12-03 14:15:34

标签: c++ templates lambda variadic-templates perfect-forwarding

我正在尝试使用嵌套的lambda捕获来构建完美的转发(零复制)构造。 我希望应该有零个副本构造,但是有些东西坏了。

我离开了可变参数arg。打包成元组(好动),然后将元组(好动)传递给std :: apply,并在最终的嵌套lambda中,我组装另一个元组(预计要好动,但包装器CTOR COPY不能移动:

aggregate(Amount ~ ID + Year, data=D, FUN=sum)

提供输出CTOR MOVE-CTOR COPY-CTOR(1、2,st,42)

1 个答案:

答案 0 :(得分:9)

import pandas as pd
import numpy as np
from fbprophet import Prophet

df['floor'] = 0

#holidays
christmas = pd.DataFrame({
  'holiday': 'christmas',
  'ds': pd.to_datetime(['2008-12-25', '2009-12-25', '2010-12-25',
                        '2011-12-25', '2012-12-25', '2013-12-25',
                        '2014-12-25', '2015-12-25', '2016-12-25',
                        '2017-12-25', '2018-12-25', '2019-12-25']),
  'lower_window': -1,
  'upper_window':  1,
})

holidays = christmas

m = Prophet(holidays=holidays,
            seasonality_mode='multiplicative',
            holidays_prior_scale=0.05
           )
m.fit(df)

future = m.make_future_dataframe(periods=365)
future['floor'] = 0

forecast = m.predict(future)
fig = m.plot(forecast)

将此更改为

return [args_upper = std::make_tuple(std::forward<Args>(args)...)]()
除非您将lambda设为return [args_upper = std::make_tuple(std::forward<Args>(args)...)]() mutable ,否则

args_upper隐式为const。这将阻止移动语义。