今天,我经常尝试在我的Phoenix应用程序中混合使用ecto.migrate,并且出乎意料地发现了以下错误:
warning: could not find repositories for application :adah.
You can avoid this warning by passing the -r flag or by setting the
repositories managed by this application in your config files:
config :adah, ecto_repos: [...]
The configuration may be an empty list if it does not define any repo.
** (Protocol.UndefinedError) protocol Enumerable not implemented for :ok
(elixir) lib/enum.ex:1: Enumerable.impl_for!/1
(elixir) lib/enum.ex:116: Enumerable.reduce/3
(elixir) lib/enum.ex:1486: Enum.reduce/3
(elixir) lib/enum.ex:609: Enum.each/2
(mix) lib/mix/cli.ex:58: Mix.CLI.run_task/2
Run Code Online (Sandbox Code Playgroud)
我的代表是:
phoenix_ecto: 3.0.0-rc.0
ecto: 2.0.0-rc.0 …Run Code Online (Sandbox Code Playgroud) 在我的代码中,我有一个类,它注册其他类的方法:
#include <iostream>
using namespace std;
template< typename C>
class Reg {
public:
template< typename R, typename A>
void register_f( string name, R ( C:: *method_p ) ( A)) { /*registration process*/ }
// template< typename R>
// void register_void_f( string name, R ( C:: *method_p ) ( void)) { /*registration process*/ }
};
class A {
public:
int f( void) { return 1; }
void g( int x) { /* some code*/ }
};
int main() {
Reg< A> …Run Code Online (Sandbox Code Playgroud) 我有与此等效的代码:
class X {};
class Y {};
template< typename T>
class C {
public:
virtual T * foo() = 0;
};
class A : public C< X> {
public:
X * foo() {};
};
class B : public A {};
class D : public B, public C< Y> {
public:
Y * foo() {}; //this is the only one method I need here. Not A::foo!
};
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
error: invalid covariant return type for 'virtual Y* D::foo()'
Y * foo() {}; …Run Code Online (Sandbox Code Playgroud) 如何编译此代码:
#include <iostream>
using namespace std;
enum E { A, B};
template< E x>
class C {
public:
#if( x == A)
static void foo() {
cout << "A";
}
#elif( x == B)
static void goo() {
cout << "B";
}
#endif
};
int main() {
C< A>::foo();
C< B>::goo();
return 0;
}
error: ‘goo’ is not a member of ‘C<(E)1u>’
Run Code Online (Sandbox Code Playgroud)
我有两个大的类只有几行不同,所以我想制作枚举模板.问题是这些行中有using关键字,所以我不知道该放什么.
有没有正确的方法呢?
PS>我必须使用C++ 03.
编辑:一点澄清.我知道template<>构造,但我不想使用它,因为这样我得到了很多代码重复.也许我可以以某种方式进行部分"模板实例化"(如果这是正确的术语template<>)?
假设我有两个类(我不会有更多):
class A {
public:
//…a …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我需要设置操作超时。感谢Timex库,这很容易做到。
可悲的是,我遇到了一个奇怪的错误。我挖了它,发现了这个:
iex(55)> dt = Timex.now() |> Timex.add( Timex.Duration.from_seconds( 10))
#DateTime<2017-12-13 18:32:30.922418Z>
iex(56)> DateTime.utc_now()
#DateTime<2017-12-13 18:32:22.411246Z>
iex(57)> dt <= DateTime.utc_now()
false
iex(58)> dt <= DateTime.utc_now()
false
iex(59)> dt <= DateTime.utc_now()
false
iex(60)> dt <= DateTime.utc_now()
false
iex(61)> dt <= DateTime.utc_now()
false
iex(62)> dt <= DateTime.utc_now()
false (!)
iex(63)> dt <= DateTime.utc_now()
true (!)
iex(64)> dt <= DateTime.utc_now()
false (!)
iex(65)> dt <= DateTime.utc_now()
false
iex(66)> dt <= DateTime.utc_now()
false
Run Code Online (Sandbox Code Playgroud)
我做错了什么?这是一个错误,还是本来就是这样的?在 Elixir 中比较两个日期时间的正确选择是什么?
PS> 我正在使用Elixir 1.5.2。
Erlang/OTP …Run Code Online (Sandbox Code Playgroud)