我需要编写一个模板化函数,根据其参数的类别,它的行为会有所不同:
template<class ContainerType>
bool myFunc(ContainerType in){
//do some stuff
}
template<class NotAContainerType>
bool myFunc(NotAContainerType in){
//do something else
}
Run Code Online (Sandbox Code Playgroud)
我被限制在C++ 11中,所以static_if不在桌面上.此外,类的ContainerType和NotAContainerType非常大,并且可能在将来发生变化,因此只需手动添加一些例外作为模板特化也是不明智的.
我知道std::enable_if解决方法,但是如果我需要将它应用于两个相互不同的类集,我该如何使用它?
当我运行代码时,它会重定向并显示
TypeError at /accounts/register cannot unpack non-iterable bool object
Run Code Online (Sandbox Code Playgroud)
问题是当我将以下条件放在我的代码中时
User.objects.filter(username==username).exists():
User.objects.filter(email=email).exists():
Run Code Online (Sandbox Code Playgroud)
请帮忙
from django.shortcuts import render, redirect
from django.contrib.auth.models import User, auth
# Create your views here.
def register(request):
if request.method == 'POST':
last_name = request.POST['Last_name']
first_name = request.POST['first_name']
username = request.POST['username']
email = request.POST['email']
password1 = request.POST['password1']
password2 = request.POST['password2']
if password1==password2:
if User.objects.filter(username==username).exists():
print("username taken")
elif User.objects.filter(email=email).exists():
print('email exists')
else:
user = User.objects.create_user(username=username,password=password1,email=email,first_name=first_name,last_name=last_name)
user.save()
print('User Created')
else:
print('password doesnt match')
return redirect('/')
else:
return render(request,'accounts/register.html')
Run Code Online (Sandbox Code Playgroud)
错误
TypeError: …Run Code Online (Sandbox Code Playgroud) 我想spring-boot-starter-web在我的项目中使用父级。不幸的是,如果我尝试使用它,我会收到以下错误消息:
[ERROR] [ERROR] 在处理 POM 时遇到了一些问题: [错误]父 POM 的包装无效 org.springframework.boot:spring-boot-starter-web:2.0.5.RELEASE,必须是“pom”但是“jar”@org.springframework.boot:spring-boot-starter -web:2.0.5.RELEASE @ [错误] 构建无法读取 1 个项目 -> [帮助 1] [错误] [错误] 项目 com.company:my-artifact:1.0-SNAPSHOT (/home/user/Projects/my-artifact/pom.xml) 有 1 个错误 [错误] 父 POM 的包装无效 org.springframework.boot:spring-boot-starter-web:2.0.5.RELEASE,必须是“pom”但是“jar”@org.springframework.boot:spring-boot-starter -web:2.0.5.RELEASE
如果我更改parent为spring-boot-starter-parent这个错误不会发生并且构建完成没有错误。
这是我的 MWE pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>my-artifact</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.5.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.version>1.2.71</kotlin.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<testSourceDirectory>src/test/kotlin</testSourceDirectory> …Run Code Online (Sandbox Code Playgroud) c++ ×1
c++11 ×1
django ×1
django-views ×1
enable-if ×1
kotlin ×1
maven ×1
python ×1
python-3.x ×1
spring ×1
spring-boot ×1
templates ×1