cageq/knet

单件能编译通过么?

Closed this issue · 1 comments

`template <class... P>
static T &instance(P... args)
{
if (s_ins)
{
return *s_ins;
}

			std::call_once(s_once, [&]() {
				s_ins = new T(args...);
			});
			return *s_ins;
		}

		static T &instance()
		{
			if (s_ins)
			{
				return *s_ins;
			}
			std::call_once(s_once, [&]() {
				s_ins = new T();
			});
			return *s_ins;
		}

`

单件写成这样应该编不过的吧?估计得写成宏才能支持多种参数的情况吧,或者能把参数保存下来么?第一次使用完整的参数,后面使用保存下来的参数?

cageq commented

use std::tuple and std::apply or add init method to singleton class