blob: aa5a8fd9bbe7d633fbc75609053b23bbe4c25e9c [file] [log] [blame]
// run
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"log"
"strconv"
)
type Setter2[B any] interface {
Set(string)
type *B
}
func FromStrings2[T any, PT Setter2[T]](s []string) []T {
result := make([]T, len(s))
for i, v := range s {
p := PT(&result[i])
p.Set(v)
}
return result
}
type Settable int
func (p *Settable) Set(s string) {
i, err := strconv.Atoi(s)
if err != nil {
log.Fatal(err)
}
*p = Settable(i)
}
func main() {
s := FromStrings2[Settable, *Settable]([]string{"1"})
if len(s) != 1 || s[0] != 1 {
log.Fatalf("got %v, want %v", s, []int{1})
}
}